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
> 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