Use STUFF
and FOR XML
:
Create and populate sample table (Please save us this step in your future questions)
DECLARE @T AS TABLE
(
Name varchar(10)
)
INSERT INTO @T VALUES
('John'),
('Vicky'),
('Sham'),
('Anjli'),
('Manish')
The query:
SELECT STUFF((
SELECT ',' + Name
FROM @T
FOR XML PATH('')
), 1, 1, '') As [output];
Results:
output
John,Vicky,Sham,Anjli,Manish
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…