?
Solved

Export MS SQL Procedure to text/csv file

Posted on 2010-09-17
7
Medium Priority
?
1,128 Views
Last Modified: 2012-05-10
Hi,

I have a MS SQL procedure that excepts a single numerical parameter which  then produces a single table of results.

I would like to export these result sets to a file so that it can be imported into an existing mysql table.

I am trying to use bcp but it only seems to produce one line and fail, this is the syntax I am using:

bcp "exec cwo.djw.ol_lcd_files 11" queryout "F:\EXPORT_LCD_OFFLINE\venues.csv" -t","  -e "C:\error.log" -c -T -SSERVER -r \r\n

the query should produce about 7000 lines but all I get is one single line like this:
2689,7068,Training 001, , , , , ,,,,, ,,,

Is anyone able to tell me where I am going wrong?  


0
Comment
Question by:darren-w-
7 Comments
 
LVL 10

Expert Comment

by:OnALearningCurve
ID: 33699539
Hi darren-w-,

have you tried encapsulating your row termination options in quotes which would give

bcp "exec cwo.djw.ol_lcd_files 11" queryout "F:\EXPORT_LCD_OFFLINE\venues.csv" -t","  -e "C:\error.log" -c -T -SSERVER -r "\r\n"

Just a shot in the dark,

Mark.
0
 
LVL 26

Expert Comment

by:Tomas Helgi Johannsson
ID: 33699575
         Hi!

It seems like your function is returning a pointer/cursor to a result-table which you need to
iterate through.


Regards,
   Tomas Helgi
0
 
LVL 26

Expert Comment

by:Tomas Helgi Johannsson
ID: 33699594
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 13

Author Comment

by:darren-w-
ID: 33699610
Hi,

this is what I'm getting from this query
bcp "exec cwo.djw.ol_lcd_files 11" queryout "F:\EXPORT\venues.csv"  -c  -SSERVER   -U user -P password -r "\r\n" -t"," -e "C:\WINDOWS\Temp\error.txt"

error:

Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][SQL Native Client]Protocol error in TDS stream
SQLState = S1000, NativeError = 0
Error = [Microsoft][SQL Native Client]Protocol error in TDS stream
SQLState = S1000, NativeError = 0
Error = [Microsoft][SQL Native Client]Protocol error in TDS stream

BCP copy out failed

I've got the feeling that it does not like the extracted data, though I would assume it should be able to handle all output?
0
 
LVL 26

Expert Comment

by:Tomas Helgi Johannsson
ID: 33699621
Forgot to mention this

From the msdn link I posted

"Is a Transact-SQL query that returns a result set. If the query returns multiple result sets, such as a SELECT statement that specifies a COMPUTE clause, only the first result set is copied to the data file; subsequent result sets are ignored. Use double quotation marks around the query and single quotation marks around anything embedded in the query. queryout must also be specified when bulk copying data from a query."

Try changing queryout to just out. :)

Regards,
   Tomas Helgi
0
 
LVL 5

Expert Comment

by:ina_don
ID: 33709094
I think your terminator could be causing the problems that you are experiencing. Instead of using -t "," could you try letting it use the default terminator or could you atleast use something else to see if the export is successful then we can work on this from there?
0
 
LVL 13

Accepted Solution

by:
darren-w- earned 0 total points
ID: 33718296
I've tried a few of these options and not had much success, now given up on this method and I've adapted a php program to do the job.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question