Solved

Export MS SQL Procedure to text/csv file

Posted on 2010-09-17
7
1,101 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-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

691 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