Solved

Export MS SQL Procedure to text/csv file

Posted on 2010-09-17
7
1,075 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 25

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 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 33699594
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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 25

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

856 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