October 31, 2005 at 3:30 pm
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
October 31, 2005 at 4:10 pm
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.
October 31, 2005 at 5:08 pm
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.
November 1, 2005 at 1:11 am
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
November 1, 2005 at 1:11 am
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
November 1, 2005 at 1:52 am
If you put SET FMTONLY ON in the head of a query then no results will be returned, only the column headers.
November 1, 2005 at 2:11 am
If you put SET FMTONLY ON in the head of a query then no results will be returned, only the column headers.
November 1, 2005 at 5:42 am
Yes, this may by a T-SQL question. Let's try this query;
select
top 0 * from YourTable
November 1, 2005 at 7:29 am
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?
November 1, 2005 at 9:16 am
So 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.
November 1, 2005 at 1:34 pm
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