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 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Export Multi SQL Scripts to One text file by BCP

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-05-26 : 09:02:26
Phoenix writes "Hi Guys,
I have a question here...I know the BCP can export SQL data to text files and I always do that. But now, I need to export more than one SQL script to a same Text file. If I do like below:

bcp "select * from northwind" queryout northwind.txt -S -U -P..
bcp "select * from westwind" queryout northwind.txt -S -U -P..

then I just get only the data from "westwind". You may say you can "copy 1.txt+2.txt northwind.txt", but I have many scripts to run here so is there any simple way to do that? Oh, pls don't tell me "select * from northwind and westwind",ha.

Great thanks!"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2006-05-26 : 09:04:11
Well, if all the databases are on the same server, why not UNION the results together:

CREATE PROCEDURE GetAllData AS
SET NOCOUNT ON
SELECT * FROM northwind
UNION ALL
SELECT * FROM westwind


bcp "exec mydb..GetAllData" queryout northwind.txt -S -U -P...
Go to Top of Page
   

- Advertisement -