Click here to Skip to main content
15,887,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts,

I have developed a SQL Query which is running fine with SSMS.
I want to run it by double clicking the file name from windows explorer.

Please give me the idea.


--- Anil Kumar
Posted

Create a batch file. Save it on desktop and run it as per need just by double clicking.
You can use SQLCmd OR OSql for it.

Steps:
1. Open one new notepad, put the sql commands that you want to excute, e.g:
SQL
USE MyDataBase
go
SELECT * FROM MyTable
go


2. Save the text file with .sql extension e.g.: SampleQuery.sql

3. Open another notepad at same folder location, put something like:
osql -S servername -U username -P password <samplequery.sql>
pause
</samplequery.sql>

4. Save this as .bat extension e.g.: MySQLQueryBatchFile.bat

5. Double click on this batch file will automatically execute the SQL query

Refer:
MSDN: sqlcmd Utility[^]
SQL SERVER – sqlcmd vs osql – Basic Comparison[^]
 
Share this answer
 
you want to hook osql.exe[^] up with File Associations[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900