You are on page 1of 1

FOR %%f IN(*.

sql) DO SQLCMD -S %1 -d %2 -U %3 -P %4 -I -i "%%f"


FOR %%f IN(*.sql) DO OSQL -S %1 -d %2 -U %3 -P %4 -i "%%f"
osql -S "Enter Server Name Here" -E -Q"exec msdb.dbo.sp_start_job 'Enter Job Nam
e Here'"
1) Example of running system command using xp_cmdshell is SQL SERVER ??Script to
find SQL Server on Network
EXEC master.. xp_CMDShell 'ISQL-L'
2) Example of running batch file using T-SQL
Here is an example to execute batch files that contains multiple Sql statments
i) Running standalone batch file (without passed parameters)
EXEC master.. xp_CMDShell 'c:findword.bat'
ii) Running parameterized batch file
DECLARE @PassedVariable VARCHAR ( 100 )
DECLARE @CMDSQL VARCHAR ( 1000 )
SET @PassedVariable = 'www.IntelligetnsiaSotware.com'
SET @CMDSQL = 'c:findword.bat' + @PassedVariable
EXEC master.. xp_CMDShell @CMDSQL

You might also like