I have a query whose results I'd like to write to a text file. I'm doing this across several Db's and output files and so would like to automate it.
I know how to do this in SSMS
by running the script with the output
set to file
but was curious if there is a way to do it in a script.
Ideally something like :
SELECT * FROM tablel
OUTPUT TO 'c:\myFile1.txt'
SELECT * FROM table2
OUTPUT TO 'c:\myFile2.txt'
SELECT * FROM table3
OUTPUT TO 'c:\myFile3.txt'
Any suggestions?