Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem exporting MS SQL Server View to CSV

Status
Not open for further replies.

RikHess

MIS
Jul 25, 2002
69
US
I have an VB app that I am attempting to teach to export a SQL View to a CSV file.

I have gotten as far as:
Code:
Set NoCount ON
exec master.dbo.xp_cmdshell 'bcp "select * from imis.dbo.vDistrictDB3" queryout "F:\data\testout.csv" -c -T -t, -Usa -Ppwd'

But there are two problems:

1. I need to enclose char fields in double quotes (the data has commas).
2. I need to include field names as the first record.

This output file will be FTPed to users and creates a file over 10 Mb when exported to an Excel file. I am thinking the CSV format would be signifantly smaller.

My plan is to set up a Stored Proc to handle this file creation, then call the SP from VB.

Final question for now, is this the way to go?

TIA for any help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top