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.
| 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_1unionselect bcpColumnfrom ... or append the header to the txt file after you create it.Nathan Skerl |
 |
|
|
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" |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-11-14 : 13:21:41
|
| select yourColumn_1select 'yourColumn_1' as yourColumn_1, seq = 1union allselect bcpColumn, seq = 2from ...) aorder by seqotherwise 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. |
 |
|
|
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 |
 |
|
|
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" |
 |
|
|
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 MadhivananFailing to plan is Planning to fail |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|