PsychoDazey
asked on
build string from select statement
I am trying to build a select statement that I will pass to a tored proc as xml. basically, I want to wrap the ids that are returned in xml tags, like this:
<id>123</id><id>234</id>
...the query statement I am trying to run looks like:
select distinct @myxml = '<id>' + convert(varchar(25), id) + '</id>'
from tbl_answers
where coalesce(IsCompleted, 0) = 0
This only returns the first value it hits (i.e. - <id>123</id>). I also tried inserting the results into a table variable and building the string by selecting one row at a time, that didnt work either, it returns a null.
Any thoughts?
<id>123</id><id>234</id>
...the query statement I am trying to run looks like:
select distinct @myxml = '<id>' + convert(varchar(25), id) + '</id>'
from tbl_answers
where coalesce(IsCompleted, 0) = 0
This only returns the first value it hits (i.e. - <id>123</id>). I also tried inserting the results into a table variable and building the string by selecting one row at a time, that didnt work either, it returns a null.
Any thoughts?
ASKER
That works until I put the distinct clause in. For some reason as soon as I do that it only returns the first record....any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect, thanks!
ASKER
sorry, forgot to accept!
Open in new window