Reputation:
Consider my Select query, I m using
Select Convert(xml, '<b>Grand Total</b>'),
Convert(xml,'<b>'+Convert(varchar,Sum(amt))+'</b>')as Amt
From myTable
For xml path(''),type //with and without results are same
Also I have more HTML tags coming from a local variable in this form:
Set @loc_var = '<Table><TR><TD>This is some dummy Text</TD></TR></TABLE>'
and so on. The above result set is finally then gets embedded within the above HTML string in somewhere.
But after the embedding final result contains the Select statements result as below and rest are fine, no problems. Kindly help.
Output:
<Table><TR><TD>This is some dummy Text</TD></TR></TABLE> <b>Grand Total</b>
DESIRED OUTPUT
<Table><TR><TD>This is some dummy Text</TD></TR></TABLE><b>Grand Total</b>
Upvotes: 1
Views: 9282
Reputation: 51
Hard to find:
SELECT @DATA = CONCAT('<br><br>',(SELECT X ,',' From MYTABLE For XML PATH (''));
After select XML path in a variable use, REPLACE:
SELECT @DATA = REPLACE(REPLACE(@DATA,'< ;','<'),'> ;','>');--THERE IS SPACE CHARACTERS, YOU SHOULD CLEAN "> ;" AND "< ;"
and then you can INSERT or SELECT @DATA
Upvotes: 2
Reputation: 122032
Try this one -
DECLARE @temp TABLE (value INT)
INSERT INTO @temp (value)
VALUES (1),(2)
SELECT '<Table><TR><TD>This is some dummy Text</TD></TR></TABLE>' + (
SELECT SUM(value) AS [text()]
FROM @temp
FOR XML PATH('b')
)
Output -
----------------------------------------------------------------
<Table><TR><TD>This is some dummy Text</TD></TR></TABLE><b>3</b>
Upvotes: 0