|
RJ
Starting Member
11 Posts |
Posted - 2011-06-22 : 07:36:29
|
| I use BCP with a format file to export data into a CSV file. This BCP process is incoorperated in a STORED PROCEDURE, which is activated by running a report. However, I require header information to be placed in the CSV file but cannot find anyway of achieving this.Is there a way of specifying headers in the format file or do I need to add it to the SP script?Here is a copy of the SP and BCP script.(@StartDate Datetime,@EndDate Datetime,@Source Int=0) ASDeclare @sql varchar(500);select cust.custno, cust.fname, cust.lname, cust.addr1, cust.addr2, cust.addr2e, cust.addr3, cust.po, cust.postcd,cust.email, cust.htel, cust.wtel, cust.tel3, cust.consent, cust.nocontact, vehi.licno, vehi.serialno, vehi.make, vehi.model, vehi.submodel,convert(varchar,vehi.fregd, 103) as RegDate,convert(varchar,vehi.nmd, 103) as NextSvcDate, convert(varchar,vehi.last_service, 103) as LastSvcDate,convert(varchar,vehi.ninspecday, 103) as NxtInspDate,convert(varchar,vehi.inspecd, 103) as LastInspDate,convert(varchar,vehi.next_emission_inspect, 103) as NxtEmiDate,convert(varchar,vehi.last_emission_inspect, 103) as LastEmiDatefrom vehijoin cust on cust.custno = vehi.custnowhere nmd between @StartDate and @EndDate if @Source = 0beginselect @sql = 'bcp "exec AMDEMSYS.dbo.A001_SVC_DATES '+ '''' + CONVERT(varchar(8),@StartDate,112) + ''''+ ',''' + CONVERT(varchar(8),@EndDate,112) + ''''+ ',1"'+ ' queryout C:\SVC_Data\SVC.CSV -S cc-rjs-xplaptop\sqlexpress -q -f C:\SVC_Data\SVC.fmt -U sa -P sa'exec master..xp_cmdshell @sqlend |
|