Sample Header Ad - 728x90

SQL script to run from batch jobs

1 vote
0 answers
160 views
I have a sql script that truncates the table and insert into database from a linked server.Since the server is SQL express I will need to use batch jobs to schedule the jobs. Below is a snippet of the batch job that calls the sql script TRUNCATE TABLE [TABLE1].[dbo].[TableData] WAITFOR DELAY '000:00:01' INSERT INTO [TABLE1].[dbo].[TableData] SELECT * FROM [SourceServer].[SourceDatabase].[dbo].[VW_View] The batch jobs works fine if I use the below code but since osql is deprecated I will need to use sqlcmd which is runs in a loop and never stops. osql -S myserver -E -i "c:\test.sql" -o "c:\output.txt" --- Runs fine sqlcmd -S myserver -E -i "c:\test.sql" ----- Does not work and goes to a loop that does not end. I will appreciate if someone can provide me the correct syntax for the sqlcmd.
Asked by SQL_NoExpert (1117 rep)
Feb 14, 2024, 12:23 PM