Include column names in export table –> textfile | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Include column names in export table –> textfile

Hi! In a DTS package I simply reads data from a table to a txt-file. But I haven´t figured out how to include the column-names in the exported file… Example how it looks like today
data1;data2;data3;
data1;data2;data3;
data1;data2;data3; Example how i want it to look like
column1;column2;column3;
data1;data2;data3;
data1;data2;data3;
data1;data2;data3; Have a great life!
/Erik
If all the columns are of varchar datatype then Select ‘column1′ as col1,’column2′ as col2,’column3’ as col3
Union All
Select col1,col2,col3 from yourTable Madhivanan Failing to plan is Planning to fail

CREATE VIEW dbo.dummy
AS
Select ‘column1′ as col1,’column2′ as col2,’column3’ as col3, 0 AS SeqNum
Union All
Select col1,col2,col3, 1 AS SeqNum from yourTable The datasource for DTS might look like
SELECT … FROM dbo.dummy ORDER BY SeqNum That way you can be sure, that the column headings appear on top. —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt?http://www.insidesql.de/blogs

cheers for the help guys!<br />sometimes the easiest are the best way to do it, right <img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ /> i was looking for like a button or something that said like "include columnnames"… whatever.<br /><br />Happy new years!
And you need to make sure that all columns are of varchar datatpye. Otherwise you need to convert them to be of varchar Madhivanan Failing to plan is Planning to fail
Hi Erik – there is an easier way <img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ /><br /><br />Right click your text file (destination), select Properties.<br /><br />Just below the file name there is a ‘Properties’ button – click it.<br /><br />On the right there’s a tick box ‘First row has column names’. <br /><br />Tick that and voila!<br /><br />Rgds<br />Bennie<br /><br />
Hi Bennie !!
Ha.. I knew it had to be something like that but i thought that button had another meaning.. cheers, have a good day! /erik
If you dont use DTS, then query is the only way [<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]<br /><br />Madhivanan<br /><br />Failing to plan is Planning to fail
Learn something new each day. Actually I’m glad not having to deal with DTS at all. [<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]<br /><br />–<br />Frank Kalis<br />Microsoft SQL Server MVP<br /<a target="_blank" href=http://www.insidesql.de>http://www.insidesql.de</a><br />Heute schon gebloggt?<a target="_blank" href=http://www.insidesql.de/blogs>http://www.insidesql.de/blogs</a><br />
]]>