Groups | Blog | Home
all groups > sql server programming > october 2004 >

sql server programming : BCP


Justin Drennan
10/14/2004 9:00:48 PM
I have a stored proc which executes a BCP. The problem is that the BCP is
some what erratic! Sometimes it hangs, sometimes it creates the .csv file.
Is there an alternative to getting some table outputted to a .csv file?



The problem I have with the CSV is that the CSV file name needs to be
created dynamically per day!


Any recommendations?



Here is the SP:



set @string1 = 'bcp "select XYZ from Server.marketing.dbo.Table1" queryout
\\fileserv\SQL\AutoMailer\G2R' + @filename + ' -T -S Server -c -t,'



Any ideas?





Bonj
10/14/2004 11:08:05 PM
You sould execute BCP from a client, not from within a stored procedure.
You show assigning the command line to a string, but presumably you are
executing it using xp_cmdshell in code you haven't listed?
In this case, it could fail due to a number of reasons, such as the file
existing and being open, the table not existing, the server not having
'Server' as a linked server, etc. etc.
Create a client program that controls the parameters for BCP and checks
these things.


[quoted text, click to view]

Justin Drennan
10/15/2004 8:09:37 AM
Hi Bonj,

I dont have the luxary of a client side application. Everything needs to be
scheduled, and the output needs to be unique.

I still have no idea how I am going to do this, if I dont use BCP!


[quoted text, click to view]

Bonj
10/15/2004 9:53:10 AM
If you can schedule a DTS using Enterprise Manager, you can put a 'run
process' task in that.
Set it up and make sure it works independently of the rest of the DTS before
deploying it.
You can have quite complex logic in DTSes, namely go down one if success,
another if fail. Check out the 'Workflow' submenu when right-clicking when
two tasks are selected. You can use an ActiveX script task to
programatically set the success or fail status I think. You can also use
global variables.

[quoted text, click to view]

AddThis Social Bookmark Button