Running batch file from ssms

  • 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

  • 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?


    Bru Medishetty

    Blog -- LearnSQLWithBru

    Join on Facebook Page Facebook.comLearnSQLWithBru

    Twitter -- BruMedishetty

  • 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?

  • 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


    Bru Medishetty

    Blog -- LearnSQLWithBru

    Join on Facebook Page Facebook.comLearnSQLWithBru

    Twitter -- BruMedishetty

  • 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