Qry

  • 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

  • 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

  • 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

  • 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/

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply