EricLynnWright
asked on
One row, seperated by commas for a list
I'm trying to get sql that will return a list of items but in ONE row and each item separated by commas.
Current:
Select col1 from table1
Results:
item1
item2
item3
Future:
Results:
item1, item2, item3
Current:
Select col1 from table1
Results:
item1
item2
item3
Future:
Results:
item1, item2, item3
Check out http://stackoverflow.com/questions/7159715/query-that-returns-comma-separated-list-and-allows-to-search-inside-it
declare @onerow varchar(max)
;with cte as
(
select distinct item1 + ' ' + item2 + ' ' + item3 as oneName
from yourtable yt
)
select @onerow = isnull(@onerow + char(13), '') + oneName
from cte b
print @oneName
small mistake
declare @onerow varchar(max)
;with cte as
(
select distinct item1 + ', ' + item2 + ' ,' + item3 as oneName
from yourtable yt
)
select @onerow = isnull(@onerow + char(13), '') + oneName
from cte b
print @oneName
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.