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
 General SQL Server Forums
 New to SQL Server Administration
 BCP

Author  Topic 

laddu
Constraint Violating Yak Guru

332 Posts

Posted - 2011-10-03 : 14:08:25
Hi,

I need to export 9 sql server tables data to pipe delimited text file.

I tried to use import/export wizard, but I can't export more than one table at a time.

So just wondering is there any BCP script that I can use for export all 9 at a time.
Appreciate your help.

Thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-03 : 14:14:18
export all tables data to single text file or 9 files?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

laddu
Constraint Violating Yak Guru

332 Posts

Posted - 2011-10-03 : 14:45:18
9 tables to 9 files, each table is different
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-03 : 15:10:29
You'll need to run 9 bcp commands. If it were a bigger number, then we could write custom code to generate the commands. But since it's only 9, I would suggest copy/paste/edit.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

laddu
Constraint Violating Yak Guru

332 Posts

Posted - 2011-10-03 : 15:45:55
Thanks!

I need a sample BCP command, export sql table data to pipe delimited file.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-03 : 15:47:24
bcp Db1.dbo.t1 out c:\t1.txt -Sserver1\instance1 -T -t| -c -r\r\n

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

laddu
Constraint Violating Yak Guru

332 Posts

Posted - 2011-10-04 : 12:56:51
above command throwing error
'-c' is not recognized as an internal or external command,
operable program or batch file.

Please advise.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-04 : 13:07:58
Sorry put double quotes around the pipe.

-t"|"

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

laddu
Constraint Violating Yak Guru

332 Posts

Posted - 2011-10-04 : 15:22:05

I successfully exported data into pipe delimited text file. What if I need the column names in the first data row. Appreciate your help.

bcp Db1.dbo.t1 out c:\t1.txt -Sserver1\instance1 -T -t"|" -c -r\r\n
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-04 : 15:36:25
That's where it gets tricky. I'd recommend using SSIS or the export wizard in SSMS for that.

If you must use bcp, you'll need to create a view that will add the column names to your result set. You'll have data type issues and will need converts for numeric data types, etc.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-10-04 : 15:37:07
Why are they going into Excel?

http://weblogs.sqlteam.com/brettk/archive/2005/04/13/4395.aspx



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -