September 15, 2009 at 12:54 pm
I have a script which has multiple (50+) individual queries which perform INSERTS and UPDATES to various tables.
When I execute the script within SQL Server Management Studio, I get progress messages in the bottom pane as expected.
When I run the same script using the -i parameter of the SQLCMD command, I only get the output from the first query, although it appears to be running correctly.
I am executing the SQLCMD command from a DOS .bat file. Regardless of whether I pipe the output to a file using the -o parameter or just monitor the actual .bat file execution, I only get output from the first query.
September 15, 2009 at 3:10 pm
Hi Phil
Can't reproduce this. Just tried the following SQL file:
PRINT 'Hello world';
GO
PRINT 'Hello new world';
GO
SELECT TOP(1) TABLE_NAME FROM INFORMATION_SCHEMA.TABLES;
GO
SELECT TOP(1) TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS;
GO
which returns all output by using "sqlcmd -i test.sql".
Greets
Flo
September 16, 2009 at 5:03 am
Flo,
Here is what I figured out yesterday afternoon:
My script did not have any GO statements in it. This allowed me to set a scalar variable to use in several individual queries. The script would run in Management Studio and all output would be generated when the script completed. When I added GO statements after each query, I then got progress messages when the script was run with SQLCMD but I can no longer use the scalar variable because it is no longer in context after the first GO statement.
Phil
September 16, 2009 at 5:24 am
Hi
Use SQLCMD variables instead of usual variables. This enables you to use one variable for the whole script (and can be used in SSMS).
Greets
Flo
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply