question

rsheik avatar image
rsheik asked

Executing SQL query in a bat file

Hi.. I have SQLSERVER installed in my lap.. I want to execute a sql query in a .bat file ... is it possible???
execute-sql-taskbat
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
vivekyadav0212 avatar image
vivekyadav0212 answered
Create a batch file using the below command - cd C:\Program Files\Microsoft SQL Server\110\Tools\Binn SQLCMD -S YOURCOMPUTERNAME\SQLEXPRESS -E -w 166 -e -i C:\BAT\script.sql -o C:\BAT\logfile.log Save this file as .bat. Here logfile.log will contain the output.script.sql will contain you SQL scripts Path may be different as per your installation. Is this you are looking for...
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
yay! sqlcmd. I see so many people still trying to use BCP.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.