Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Developers

My question is regarding sql server bcp utility:

How do I export data from sql server into excel sheet with the following extensions e.g. xls,xlsx, and xlsb using bcp tool, because I can export to .csv file and .txt file extensions but with excel it can not be open after exporting with bcp.

Any worker around to export into excel sheet will do help alot.

Thanks for your help in advance

Regards Lucky Khoza
Posted
Comments
_Asif_ 4-Feb-16 4:28am    
what is it so necessary to export in the .xls, .xlsx formats? .CSV is suffcient as it can be open in excel easily
_Asif_ 4-Feb-16 4:33am    
can you share your bcp command which you are using to export
Mrkhoza 4-Feb-16 7:21am    
Hi _Asif_

Our clients need xls or xlsx or xlsb files

DECLARE @cmd VARCHAR(512);
SET @cmd = 'bcp "SELECT * FROM AssetRegister WHERE FinancialAccountingPeriodID = ''4'';" queryout "C:\2014_Jul01_Jul31_AssetRegister201602040830.csv" -c -d VSmart3.Test -t, -S ZAV-TTY-DEV1\SQL2008R2 -T'
Exec xp_cmdshell @cmd

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900