Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting column names in a query

Status
Not open for further replies.

takaoki

Programmer
Aug 28, 2008
39
ZA
Hi,

I am using SSIS to run a stored proc. The results of the stored proc are then written to a file.

The problem I am having is that I can't figure out a way to get the column names into the file from the SSIS side (another issue).

So, I was thinking if I could write the query such that it puts the column names in the first row, that would work too.

Does anyone know of a way to write a query to get the column names to appear as the first row of data from the query?

Thanks!
 
Here's one way. It isn't elegant but it works. Good luck!

Code:
SELECT Column1, Column2 FROM (
  SELECT 1 AS SortIt,
    'Column1' AS Column1, 'Column2' AS Column2
  FROM ...etc...
  UNION ALL
  SELECT 2 AS SortIt,
    Column1, Column2
  FROM ...etc...
) a ORDER BY SortIt

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top