November 17, 2009 at 4:50 pm
I am trying to execute one batch file from the ssms using following code
EXEC master..xp_CMDShell 'C:\Test.bat'
The batch file is attached here in the txt format.
My output is as follows:
output
NULL
C:\WINNT\system32>use automationDB12Nov
'use' is not recognized as an internal or external command,
operable program or batch file.
NULL
C:\WINNT\system32>go
'go' is not recognized as an internal or external command,
operable program or batch file.
NULL
C:\WINNT\system32>select COUNT(1) from OtherOperatorCodes
'select' is not recognized as an internal or external command,
operable program or batch file.
NULL
Why this is not getting executed:(?
-Lk
November 17, 2009 at 5:23 pm
By Looking at the error. you are using USE, GO , SELECT Keywords in batch file, which are SQL commands and cannot be run in dos prompt, the error is indicating as not recognized internal or external command.
Can you explain why is this being done?
Blog -- LearnSQLWithBru
Join on Facebook Page Facebook.comLearnSQLWithBru
Twitter -- BruMedishetty
November 17, 2009 at 7:22 pm
This is a demo which I am trying to run many sql queries in the batch file later. The batch file can contain the T-sql commands but I feel that I need to give server name in the batch file. I am not sure... Anyone knows about this?
November 17, 2009 at 7:45 pm
luckysql.kinda (11/17/2009)
This is a demo which I am trying to run many sql queries in the batch file later. The batch file can contain the T-sql commands but I feel that I need to give server name in the batch file. I am not sure... Anyone knows about this?
I agree that you can run T-SQL queries from command prompt, it can be done using sqlcmd command line utility. My question in the previous reply was, you are using T SQL as general SQL statement instead of using sqlcmd.
Please find the link below for more information on Sqlcmd.
http://www.sqlbook.com/SQL-Server/SQLCMD-command-line-utility-13.aspx
http://msdn.microsoft.com/en-us/library/ms162773.aspx
Blog -- LearnSQLWithBru
Join on Facebook Page Facebook.comLearnSQLWithBru
Twitter -- BruMedishetty
November 17, 2009 at 7:54 pm
Thanks Bru for correct links. This is how I should have executed from command prompt.
sqlcmd -S SQLServer05 -i C:\Test.bat
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply