HTML Query Result format

 

 

SET @tableHTML =

N'<table>' +

N'<tr><th>SpecialOfferID</th>

<th>Description</th>

<th>Type</th>

<th>Category</th>

<th>StartDate</th>

<th>EndDate</th>

</tr>' +

CAST ( (

SELECT td = CAST([SpecialOfferID] AS VARCHAR(100)),'',

td = [Description],'',

td = [Type],'',

td = [Category] ,'',

td = CONVERT(VARCHAR(30),[StartDate],120) ,'',

td = CONVERT(VARCHAR(30),[EndDate],120)

FROM [AdventureWorks].[Sales].[SpecialOffer]

ORDER BY [SpecialOfferID]

FOR XML PATH('tr'), TYPE

) AS NVARCHAR(MAX) ) +

N'</table>'