Thursday, December 29, 2011

running multiple scripts in MSSQL

  1. Create the script
  2. :setvar workpath "c:\scripts\"
    :setvar FileToexecute "test3.sql"
    --:r $(workpath)$(FileToexecute)
    :r $(workpath)test1.sql
    :r $(workpath)test2.sql
  3. enable SQLCMD mode
  4. Run the above query

enabling the SQLCMD mode
using :r
joining :r with variables
unable to use buildin sqlcmd variables

1 comment:

  1. batch file solution

    for /f "usebackq tokens=*" %%a in (`dir /b/on *.sql`) do (
    echo:%%~nxa
    sqlcmd -U %uid% -P %pwd% -i %%~nxa
    echo.
    )

    ReplyDelete