‘%1!’ must be the first statement in a query batch.

Error Message:
Msg 111, Level 15, State 1, Line 7
‘%1!’ must be the first statement in a query batch.

Severity level:
15.

Description:
This error message appears, when you try to execute statements in a batch that need to be separated in different batches or that need to executed in a different order in the same batch.

Consequences:
The SQL statement cannot be parsed and further execution is stopped.

Resolution:
Error of the Severity Level 15 are generated by the user and can be fixed by the SQL Server user. The conflicting statements must either be separated by a batch separator (default GO), or, if possible from the point of view of your program logic executed in a different order. However, in most case restructuring of the order of statements will not be possible so that you have to resort to the separation in different batches.

Versions:
All versions of SQL Server.

Example(s):
USE tempDB

CREATE TABLE t
(
 c1 INT NOT NULL
)
CREATE FUNCTION dbo.udf(@now DATETIME)
RETURNS DATETIME
AS
BEGIN RETURN @now
END

DROP TABLE t
DROP FUNCTION dbo.udf

Remarks:
In the above example, the CREATE FUNCTION statement needs to be executed as the first statement of a new batch.




Array

No comments yet... Be the first to leave a reply!