troubleshooting Question

SQL Server BCP export to CSV

Avatar of Steve7423
Steve7423Flag for Canada asked on
Microsoft SQL Server 2008SSIS
7 Comments1 Solution1425 ViewsLast Modified:
All the searches and posts I've come across use the following to export data to a CSV file, how ever I can't get it to work.

Here's a wrinkle, the file doesn't exist, the export has to create it.  

How do I get BCP export to create the file and write data ???

I've created a #temp table with the records and now I need to use a select statement to get a single record from the #temp and create and write the file.  How do i do this??

This is being done from within a proc.

Create Table #Temp
[  ..]

Declare @CSVexport varchar(8000)
set @CSVexport = 'BCP select
      [Fld 1]
        ,[Fld 2]
        ,[Fld 3]
        ,[Fld 4]
        ,[Fld 5]
        ,[Fld 6]
      From #temp where [Fld 7] = @ClientDocNo out C:\Test -c -T -S SERVER'
Exec master..xp_cmdshell @CSVexport

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros