Answered columns in select list

  • Thursday, October 13, 2005 10:27 AM
     
     

    hi friends!

    Suppose, i have a query:

    SELECT fname AS Firstname, lname AS Lastname FROM Customer

    Now is it possible to get the column names produced by the above query? Like

    Firstname
    Lastname

    just like we extract column names from information_schema.columns for a table name?

    with regards,
    Buragohain

All Replies

  • Thursday, October 13, 2005 7:31 AM
     
     Answered
    In your client, sure -- every client library can do that.  In SQL Server, probably not.
     
    What is the business or technical problem you're trying to solve?  Perhaps we can come up with a better way of handling it.

    --
    Adam Machanic
    SQL Server MVP
    http://www.datamanipulation.net
    --
     
     

    hi friends!

    Suppose, i have a query:

    SELECT fname AS Firstname, lname AS Lastname FROM Customer

    Now is it possible to get the column names produced by the above query? Like

    Firstname
    Lastname

    just like we extract column names from information_schema.columns for a table name?

    with regards,
    Buragohain

  • Thursday, October 13, 2005 1:22 PM
     
     
    What are you consuming it with? ADO with vb? ado.net ?
  • Friday, October 14, 2005 5:12 AM
     
     
    Hi friends!
    Thanx everyone for your response.

    By creating a temporary table using the query, then accessing the columns, and then deleting the temporary table, will solve the problem. But i wonder is there any in-built technique is Sql server for that or not. Like:

    exec sp_columns 'Customer'

    exec sp_columns 'select * from Customer'  (wrong)

    exec sp_columns 'SELECT fname AS Firstname, lname AS Lastname FROM Customer'  (wrong)

    Again, if there is any technique in ADO.NET, then it will be helpfull too.

    (my problem was to show friendly column names to end user from several tables joined.)

    with regards,