Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

Export query into csv with a .sql file

Hello Experts,

I am looking for a sqcmd, bcp, or a VBscript that:

Read a File.sql  which contains a Complex select and queryout  into a csv.

I am aware of the following version:

 sqlcmd -S MyServer -d myDB -E -Q "select col1, col2, col3 from SomeTable"
       -o "MyData.csv" -h-1 -s"," -w 700

However I would like to avoid typing the query in the file I would like to call a File.sql and queryout so I don't know if something like this can work:

 sqlcmd -S MyServer -d myDB -E -Q "File.sql"
       -o "MyData.csv" -h-1 -s"," -w 700

Thank you in advance for your help.
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Luis Diaz

ASKER

It works, thank you very much!