January 7, 2013 at 2:55 am
In my table i have following result sets
sno
101
102
103
105
106
107
i want following structures
101,102,103,105,106,107
January 7, 2013 at 3:36 am
Hi
Difficult without a little more information however this may point you in the right direction
declare @table as table
(id int)
INSERT INTO @table
SELECT 100 UNION ALL
SELECT 101 UNION ALL
SELECT 102 UNION ALL
SELECT 103 UNION ALL
SELECT 104
SELECT STUFF((SELECT ',' + CAST(id AS VARCHAR (3)) FROM @table t1 ORDER BY t1.id FOR XML PATH('')),1,1,'')
Andy
==========================================================================================================================
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila. Mitch Ratcliffe
June 18, 2013 at 5:19 am
Hi ,
You can do as
declare @table as table
(id int)
INSERT INTO @table
SELECT 100 UNION ALL
SELECT 101 UNION ALL
SELECT 102 UNION ALL
SELECT 103 UNION ALL
SELECT 104
declare @output as varchar(max)
set @output='';
select @output=@output+','+cast(id as VARchar) FROM @table t1
select substring(@output,2,LEN(@output)-1) as Seq
June 18, 2013 at 7:24 am
ajayvinay1979 (6/18/2013)
Hi ,You can do as
declare @table as table
(id int)
INSERT INTO @table
SELECT 100 UNION ALL
SELECT 101 UNION ALL
SELECT 102 UNION ALL
SELECT 103 UNION ALL
SELECT 104
declare @output as varchar(max)
set @output='';
select @output=@output+','+cast(id as VARchar) FROM @table t1
select substring(@output,2,LEN(@output)-1) as Seq
Good solution, but please note that this thread is more than 5 months old.
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply