Running a Stored Procedure from a Batch File

  • Hello Everyone

     

    Just wondering if it was possible to run a stored procedure from a batch file, and if so. how would one write the query:

     

    eg: Save the statement below in a .bat file ?

    SP_FormatName 'TEST_TABLE'


    Kindest Regards,

    John Burchel (Trainee Developer)

  • Take a look at Osql.exe, or bcp in sql server books online

     

  • Or, run VBScript (either from batch file, or instead of batch file.  Then, either:

    1. Create ADO connection object and run the Execute method.  See "ADO Samples" in BOL.
    2. Create SQLDMO object and run ExecuteImmediate or ExecuteWithResults methods (depending on sproc results).

    Hope this helps



    Mark

  • Or, simply put the line below in a batch file:

    isql /U sql_username /P sql_password /S servername /i k:\filename.sql /o k:\logfile.log

    And put yout T-SQL commands in the filename.sql file.

     

     

     

  • or if you do not wish to use an input file then

    osql -Q "EXEC SP_FormatName 'TEST_TABLE'" /U sql_username /P sql_password /S servername /o logfilename

    Far away is close at hand in the images of elsewhere.
    Anon.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply