Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Qry Expand / Collapse
Author
Message
Posted Monday, January 07, 2013 2:55 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Saturday, April 19, 2014 6:20 AM
Points: 61, Visits: 368
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
Post #1403502
Posted Monday, January 07, 2013 3:36 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Today @ 2:10 AM
Points: 673, Visits: 2,636
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
Post #1403517
Posted Tuesday, June 18, 2013 5:19 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, January 18, 2014 8:18 AM
Points: 12, Visits: 35
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
Post #1464575
Posted Tuesday, June 18, 2013 7:24 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 3:57 AM
Points: 2,570, Visits: 4,655
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.



Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1464650
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse