Convert Row Values into Column

  • Check this out...

    Declare @sSqlC varchar(1000)

    select @sSqlC = COALESCE(@sSqlC + ',','') + ' ''' + cast(tblDating.[Date] as varchar(20)) + ''' As Col' + cast(tblDating.id as varchar) from tblDating

    set @sSqlC = 'Select ' + @sSqlC

    --Select @sSqlC

    Exec(@sSqlC)

    Thanks

    Atif Sheikh

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Sometimes, winning is not an issue but trying.
    You can check my BLOG
    [font="Arial Black"]here[/font][/url][/right]

  • plz Check this...

    I think it is useful for you

    declare @lsstr as varchar(750)

    declare @lssql as varchar(500)

    set @lsstr = ''

    select @lsstr = @lsstr + ',[' + 'C' + convert(varchar(5),row_number() over(order by date)) + ']' from dating

    set @lsstr = substring(@lsstr,2,len(@lsstr))

    select @lsstr

    set @lssql = 'select ' + @lsstr + ' from '

    set @lssql = @lssql + '(select ''C'' + convert(varchar(5),row_number() over(order by date)) slno,date from dating ) a '

    set @lssql = @lssql + 'pivot (max(date) for slno in (' + @lsstr + ')) as p '

    print @lssql

    exec(@lssql)

  • Me too in need of same kind of requirement....help pls...

  • bhuvaneshwari_m (3/3/2009)


    Me too in need of same kind of requirement....help pls...

    http://www.sqlservercentral.com/articles/cross+tab/65048/

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 31 through 33 (of 33 total)

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