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

I have the following set Query. how Can I run it inside from a batch Script.

declare @StartDate datetime set @StartDate=getdate()-30
declare @EndDate datetime set @EndDate=GETDATE()

exec SP_Name @StartDate,@EndDate

Any help would be appreciated.
Posted

osql -S [MyServer] -d [MyDatabase] -E -i ["C:\Test\SQLScriptProcedure.sql"] -n -b

Create a SQL Script file SQLScriptProcedure.sql as shown below..
SQL
declare @StartDate datetime set @StartDate=getdate()-30
declare @EndDate datetime set @EndDate=GETDATE()

exec SP_Name @StartDate,@EndDate

Use the following snippet to write a log..
osql -S [MyServer] -d [MyDatabase] -E -i ["C:\Test\SQLScriptProcedure.sql"] -n -b -o [Output.log]

Use the following snippet to execute multiple SQL script files
for %%f in (*.sql) do 
(
   osql -S [MyServer] -E -d [MyDatabase] -i %%f >> [Output.log]
)
pause
 
Share this answer
 
v2
 
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