Columns name from ODBC as data

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
Luk
Participant
Posts: 133
Joined: Thu Dec 02, 2004 8:35 am
Location: Poland
Contact:

Columns name from ODBC as data

Post by Luk »

Is it possible to catch columns names from SQL querry by ODBC stage and put it i.e. to a file??
LUK
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Do you mean 'first row is column names' property in seq file?
Luk
Participant
Posts: 133
Joined: Thu Dec 02, 2004 8:35 am
Location: Poland
Contact:

Post by Luk »

no!

I have ODBC stage and I am connecting to MSSQL server. I want to get column names from SQL server as data (in rows) and use them - put into target!
LUK
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Select the columns as hard-coded value in a separate SQL and call it just before your SQL followed and suffix it with ' UNION '.
mhester
Participant
Posts: 622
Joined: Tue Mar 04, 2003 5:26 am
Location: Phoenix, AZ
Contact:

Post by mhester »

If what you want are the column names from a particular table and stream this as data to a target then you could use a query like the following to select a list of column names -

Code: Select all

select COLUMN_NAME from information_schema.columns
where table_name = 'TABLE_NAME'
Make sure you are connecting to the correct database for what you are doing and replace TABLE_NAME with the table you want or leave out the WHERE and it will return all columns.
Luk
Participant
Posts: 133
Joined: Thu Dec 02, 2004 8:35 am
Location: Poland
Contact:

Post by Luk »

thanks - it is working
LUK
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Can you post the solution you have successfully implemented so any future search for similar requirements can make use of it.
Luk
Participant
Posts: 133
Joined: Thu Dec 02, 2004 8:35 am
Location: Poland
Contact:

Post by Luk »

Can you post the solution you have successfully implemented so any future search for similar requirements can make use of it.
Sainath - solution is already posted. mhester gave it!!!

Code: Select all

elect COLUMN_NAME from information_schema.columns
where table_name = 'TABLE_NAME'
LUK
Post Reply