Search code examples
sqlsql-serverbatch-filesqlcmd

SQL server Jobstep output to run bat file


I have sql job which has many job steps and each jobstep produces sql output which i need to run on the target envrionment. To run the sql job step outputs on target environment, i have batch file which includes list of .sql files.

My problem is when job step output created, it would include job step information in the firstline and also [SQLSTATE 01000].

I need to strip off the first line and replace [SQLSTATE 01000] with empty strings for all the .sql files in the directory.

What would be the best way to achieve this.

I am using sql server 2008 r2.

Thanks in advance


Solution

  • @ECHO =========================Batch File==================== @ECHO This example will create a database in Sql Server. It will simply execute the sql script created in directory... msg * hello for %%G in (C:\B*.sql) do sqlcmd -S INDIA55-PPC\SQLEXPRESS -U sa -P pass -d DatabaseName -i "%%G"

    pause