I want to create a CMD file which can run a saved query(Data export) and save the result in a particular file. Please help.
I want to run a query with CMD file
In Windows download and install Microsoft Command Line Utilities 15 for SQL Server 32 or 64 bit.
In batch file: sqlcmd -S server\sql_server -d database -q "yourQuery" > file.txt or sqlcmd -S server\sql_server -d database -q "yourQuery" > \path_to_file\file.txt or sqlcmd -S server\sql_server -d database -i "\path_to_file\file.sql" > file.txt or sqlcmd -S server\sql_server -d database -i "\path_to_file\file.sql" > \path_to_file\file.txt
In Windows download and install Microsoft Command Line Utilities 15 for SQL Server 32 or 64 bit.
In batch file:
sqlcmd -S server\sql_server -d database -q "yourQuery" > file.txt
or
sqlcmd -S server\sql_server -d database -q "yourQuery" > \\path_to_file\file.txt
or
sqlcmd -S server\sql_server -d database -i "\\path_to_file\file.sql" > file.txt
or
sqlcmd -S server\sql_server -d database -i "\\path_to_file\file.sql" > \\path_to_file\file.txt
sqlcmd -S server\sql_server -d database -q "yourQuery" > \path_to_file\file.txt
If I want to run above query, I should replace
server with Server name
database with Database name
yourQuery with query I want to run
path_to_file\file.txt with destination path and filename.
is my understanding correct?
Please login to leave a reply, or register at first.