Msg 111, Level 15, State 1, Line 7
‘%1!’ must be the first statement in a query batch.
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.
The SQL statement cannot be parsed and further execution is stopped.
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.
All versions of SQL Server.
CREATE TABLE t
c1 INT NOT NULL
CREATE FUNCTION dbo.udf(@now DATETIME)
BEGIN RETURN @now
DROP TABLE t
DROP FUNCTION dbo.udf
In the above example, the CREATE FUNCTION statement needs to be executed as the first statement of a new batch.