I'm trying to use BCP
to export my data to a .TXT
file, but I needed to do an incremental in the same file, since I will need to export data from two views.
Example:
SET @cmd = '"SELECT * FROM Site"'
SELECT @sql = 'bcp '+@cmd+' queryout D:\mytest.txt -c -t; -T -S SERVER-PC\SQLEXPRESS';
EXEC xp_cmdshell @sql;
SET @cmd = '"SELECT * FROM Customers"'
SELECT @sql = 'bcp '+@cmd+' queryout D:\mytest.txt -c -t; -T -S SERVER-PC\SQLEXPRESS';
EXEC xp_cmdshell @sql;
Data out:
H;04399024100427;20160620
V;04399024100427;CUSTOMER I;STATE;CITY;NAME;75123390;A
I thought of UNION ALL but the structure of the tables are different and I have cases where I will need to export data from up to 5 tables.