Getting column headers

  • Is there any way to get the column headers from a query? For example, I have a query that returns 4 cols and one that returns 3 cols. Is there anyway to retreive the column headers returned in each result set?

    Thanks

  • I'm not exactly sure what your asking.

    Are you using query analyzer?

    Unless you are creating derived/calculated columns, you should be able to see the headings.

     

  • That's part of the native client interface layer (what used to be called dblib).  If you were programming in C directly to it you can get them.  I was also able to get to them using whatever the heck object/class in the .NET framework (I don't remember the methods.)  I'm not sure how or if ODBC handles it.

    How are you connecting to the database?  This is not a T-SQL question but a client side programming question.

     

  • If you use .NET (presumably ) and load a dataset from the query you should be able to get the columnnames from the table definition.

    /HL

  • If you use .NET (presumably ) and load a dataset from the query you should be able to get the columnnames from the table definition.

    /HL

  • If you put SET FMTONLY ON in the head of a query then no results will be returned, only the column headers.

  • If you put SET FMTONLY ON in the head of a query then no results will be returned, only the column headers.

  • Yes, this may by a T-SQL question. Let's try this query;

    select

    top 0 * from YourTable

     

  • This is not for client side. This is being changed to T-SQL from an existing system that uses C++ to retrieve the column headers. So it sounds like T-SQL isnt useful for retreiving column headers then?

  • quoteSo it sounds like T-SQL isnt useful for retreiving column headers then?

    Depends on what you want and how you want to use it

    C++ can only get Column Headers (column names) from either the name colection of the resultset, accessing the table info using DMO or querying the syscolumns (or better INFORMATION_SCHEMA.COLUMNS)

    If you want a resultset containing rows of column names then you can use

    SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'tablename'

    Can you explain what you are doing and why so that we can give more detailed answer

    Far away is close at hand in the images of elsewhere.
    Anon.

  • I am now getting them with .NET using C#. Thanks for your help!

Viewing 11 posts - 1 through 10 (of 10 total)

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