Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 BCP With Headers

Author  Topic 

mfemenel
Professor Frink

1421 Posts

Posted - 2005-11-14 : 11:50:25
Trying to bcp from a query out to a text file. I need to include the column headings but can't find a parameter for BCP that would let me do this. Any ideas?

Mike
"oh, that monkey is going to pay"

nathans
Aged Yak Warrior

938 Posts

Posted - 2005-11-14 : 12:14:27
You could just force them into the resultset with a union...

select 'yourColumn_1' as yourColumn_1
union
select bcpColumn
from ...


or append the header to the txt file after you create it.

Nathan Skerl
Go to Top of Page

mfemenel
Professor Frink

1421 Posts

Posted - 2005-11-14 : 13:12:58
I'm a big dumb animal for not thinking of that myself. Thanks!

Mike
"oh, that monkey is going to pay"
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-11-14 : 13:21:41
select yourColumn_1
select 'yourColumn_1' as yourColumn_1, seq = 1
union all
select bcpColumn, seq = 2
from ...
) a
order by seq

otherwise the headings might not be at the top.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2005-11-14 : 13:27:45
Ah yes, ordering would be crucial in that scenario :)

Good catch, Thanks Nigel.

Nathan Skerl
Go to Top of Page

mfemenel
Professor Frink

1421 Posts

Posted - 2005-11-14 : 13:30:56
Yeah, I played with the ordering. I have a record_id field which I included in my result set and made the heading for that column 0 so it always floats to the top. Thanks guys.

Mike
"oh, that monkey is going to pay"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-15 : 00:27:53
You may need to convert the numeric columns to varchar if any

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-11-15 : 10:10:53
http://weblogs.sqlteam.com/brettk/archive/2005/04/13/4395.aspx



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page
   

- Advertisement -