Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bcp - exporting column names

76 views
Skip to first unread message

romshan

unread,
Jul 29, 2003, 8:41:50 AM7/29/03
to

Hi ,

Im using bcp for exporting to csv file.
Is there anyway i can also export the column name.
I know its possible using osql or dts but can bcp somehow give the same
functionality or is there some work around?

Thanks

romshan

--
Posted via http://dbforums.com

lindawie

unread,
Jul 29, 2003, 9:50:20 AM7/29/03
to
romshan,

> Im using bcp for exporting to csv file.
> Is there anyway i can also export the column name.
> I know its possible using osql or dts but can bcp somehow give
> the same functionality or is there some work around?

No, bcp does not have that functionality. Two possible workarounds:

1. Create a text file with the headers and the desired field
separator.
Bcp out the data to a second file, then concatenate the two files
with
the COPY command:

C:\SQLFAQ\Bcp>copy header.txt + data.txt headerdata.txt

2. Create a view that contains both the headers and the data.
You will need to convert all numeric data to varchar data type.
Using pubs..authors as an example:

create view authorshdr as
select * from (
select top 100 percent
au_id,
au_fname,
au_lname,
phone,
address,
city,
state,
zip,
contract
from (
select 1 seq,
'au_id' au_id,
'au_fname' au_fname,
'au_lname' au_lname,
'phone' phone,
'address' address,
'city' city,
'state' state,
'zip' zip,
'contract' 'contract'
union all
select 2 seq,
au_id,
au_fname,
au_lname,
phone,
address,
city,
state,
zip,
cast(contract as varchar(4))
from authors
) x
order by seq, au_id
) y


/***

bcp pubs..authorshdr out authorshdr.dat -c -T -Syourserver

***/

Linda


romshan

unread,
Jul 29, 2003, 11:42:18 PM7/29/03
to

thanx for that
will do one of the above
0 new messages