December 15, 2003 at 5:52 am
How can I use bcp to output multiple result sets to a csv file. That is running several select * from different tables and outputting the results to a single csv file.
Is there any other way of doing this?
Thanks.
December 15, 2003 at 9:13 am
bcp each select into different file and then concatenate files.
or
If all the selects have same columns then use union.
or
Concatenate each column (converting to char/narchar if necessary) into single column with comma separator and use union to join all selects together.
Edited by - davidburrows on 12/15/2003 09:13:52 AM
Far away is close at hand in the images of elsewhere.
Anon.
December 16, 2003 at 4:21 am
solutions 1 and 3 will be my best bet. Can you give me examples of how these can be done?
Thanks.
December 16, 2003 at 5:26 am
bcp "SELECT col1,col2 FROM databasename..tablename"
queryout file1.csv -S server -u username -P password -c -t ","
bcp "SELECT col1,col2 FROM databasename..tablename" queryout file2.csv -S server -u username -P password -c -t ","
copy /A file1.csv+file2.csv file.csv
bcp "SELECT cast(col1 as varchar)+','+col2 FROM databasename..tablename
UNION
SELECT cast(col1 as varchar)+','+col2 FROM databasename..tablename"
queryout filex.csv -S server -u username -P password -c
Far away is close at hand in the images of elsewhere.
Anon.
December 16, 2003 at 5:58 am
Thanks for your help.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy