Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 BCP

Author  Topic 

JAdauto
Posting Yak Master

160 Posts

Posted - 2009-09-17 : 17:29:15
Does BCP only work at a command prompt? Can it be coded in QA or in a stored procedure? I'll need to create a CVS file of our database on a nightly basis and I am not sure i know the best way to accomplish this. I am not finding as much literature on BCP as I would like. Suggestions?

YellowBug
Aged Yak Warrior

616 Posts

Posted - 2009-09-17 : 17:42:10
BCP is a command line utility. If you have xp_cmdshell enabled (not recommended) you can run it from the QA.

Here's a good link:
http://www.simple-talk.com/sql/database-administration/creating-csv-files-using-bcp-and-stored-procedures/
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-09-17 : 17:43:54
SQL-DMO and SMO also have a BulkCopy object that you can invoke programatically via COM and/or .Net. It is documented in Books Online. Although using the command line utility is probably easier.
Go to Top of Page

JAdauto
Posting Yak Master

160 Posts

Posted - 2009-09-24 : 15:26:29
Is there another "table export" feature available that would give me the option to exclude some fields?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-09-24 : 15:46:15
bcp has a "queryout" out option that can run any SELECT statement or stored procedure that returns rows.
Go to Top of Page

JAdauto
Posting Yak Master

160 Posts

Posted - 2009-09-24 : 22:19:31
I have the bcp working now using only the fields I want from the query and can make a set of these and automate it. the last thing and I am afraid to ask becuase I am afraid I already know the answer. Is there a way to include the column headers using the BCP utility?
Thx!!
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-09-25 : 00:02:59
Sadly, no. You'd have to generate the headers manually and copy them to a new file, it's a pain in the ass. But you can use sqlcmd or osql to include column names as a header. You will have less control over the output though, you'll have to experiment to get the output you want.
Go to Top of Page
   

- Advertisement -