how to run a .sql script from a .bat file with out writing a dbname inside

  • hi,

    this is how i call my files

    sqlcmd -S LA -U sa -P ppp  -i "D:\r1.sql"

    but i want to call like following ( like i call stored procedure)

    sqlcmd -S LA -U sa -P ppp  -Q "use srdb EXEC abc

    q1) in first way i have to write database name in r1.sql on each server.

    where as in second way use databse is written in .bat file i need that kind of calling , and for that i have to convert all my scripts like r1.sql to stored procedure , so pls tell me is there any way that i can call r1.sql with out putting databse name inside on diffrent server.

    yours sincerely

     

     

     

     

  • You can use the -d switch and pass it a database name on the SQLCMD call, which will automatically issue a use command as part of the connection.

     

    sqlcmd -S LA -U sa -P ppp -d MyDB -i "D:\r1.sql"

Viewing 2 posts - 1 through 1 (of 1 total)

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