Convert column results to coloumn headings

  • create table #temptable(Name varchar(25))

    GO

    insert into #temptable values('Larry');

    insert into #temptable values('Moe');

    insert into #temptable values('Curley');

    select * from #temptable

    Name

    ------

    Larry

    Moe

    Curley

    I never know what the resulst will be but I want them to be column headinds

    Larry Mo Curley

  • Column headings where? And what will be displayed under them?

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • The columns would be the results of the select statement

    select * from #temptable

    Name Larry Moe Curley

    ----- ----- ---- ------

    Larry

    Moe

    Curley

  • Where are you going to use these columns and what kind of data will be under them?

    If you want to return empty recordset with "columns" to the client application, then you should do this in the application itself, not in t-sql, as its not designed for this sort of work...

    However, it can be done using dynamic sql

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Data will be put in those columns from another table later. Right now i just want the columns added and have them blank

  • That would be very bad desing. You should not do it in T-SQL.

    As to achieve it you will need to write everything in dynamic SQL for no benefits at all.

    How you going to add data later on when you don't know the how many columns you will have? Dynamic SQL again...

    So, do it in the client up.

    Or

    There are some samples on i-net:

    http://www.simple-talk.com/community/blogs/andras/archive/2007/09/14/37265.aspx

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

Viewing 6 posts - 1 through 5 (of 5 total)

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