I have a select
query that returns one column and I want to convert that to string rows separated with ','
Select name
from tblUsers
Gives a result:
Row1; asieh
Row2:amir
Row3:safoora
I want to return
Row1: asieh,amir,safoora
Answer
MS SQL Server 2008 Schema Setup:
CREATE TABLE tblUsers
([name] varchar(7))
;
INSERT INTO tblUsers
([name])
VALUES
('asieh'),
('amir'),
('safoora')
;
Query 1:
SELECT STUFF((
select ','+ name
from tblUsers
FOR XML PATH('')
)
,1,1,'') AS names
| NAMES |
|--------------------|
| asieh,amir,safoora |
No comments:
Post a Comment