I am trying to build an HTML structure like this:
<tr><TD>John Doe (98210)</TD><TD>0.50</TD></tr><tr><TD>jane Smith (98006)</TD><TD>0.25</TD></tr><tr><TD>Total</TD><TD>0.75</TD></tr>
However, when I try to union the following two statements I receive errors. They run independently, but when I try to UNION...
Msg 156, Level 15, State 1, Line 8Incorrect syntax near the keyword 'FOR'.
Msg 156, Level 15, State 1, Line 18
Incorrect syntax near the keyword 'FOR'.
(SELECT cast(#LeadOT.EmployeeName as varchar) + ' (' + cast(#LeadOT.ADPFileNumber as varchar) + ')' AS [TD] ,cast(sum(#LeadOT.LeadOT) AS NUMERIC(36, 2)) AS [TD] FROM #LeadOT WHERE Warehouse = 782 AND #LeadOT.LeadOT <> 0.00 GROUP BY #LeadOT.EmployeeName, #LeadOT.ADPFileNumber FOR XML raw('tr'), Elements) UNION (SELECT 'Total ' as [TD] ,cast(sum(#LeadOT.LeadOT) as varchar) as [TD] FROM #LeadOT WHERE warehouse = 782 GROUP BY warehouse FOR XML raw('tr'),Elements)
Why do I receive errors when trying to UNION the above statements?