We help IT Professionals succeed at work.
Get Started

Export query into csv with a .sql file

Luis Diaz
Luis Diaz asked
on
154 Views
Last Modified: 2015-03-19
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.
Comment
Watch Question
Software Engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE