Must declare the variable '%.*ls'.

Error Message:
Server: Msg 137, Level 15, State 2, Line 3
Must declare the variable ‘@orderid’.

Severity level:
15.

Description:
SQL Server allows to use variables in SQL scripts or statements. This error is raised when you refer to a variable without having it declared first.   

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.

Versions:
All versions of SQL Server.

Example(s):
SELECT *
  FROM Northwind..Orders
 WHERE OrderID = @orderid

Remarks:
To turn the above statement into a valid one, you would need to declare the variable @orderid prior to its use. Such as: DECLARE @orderid INT
SET @orderid = 10000
SELECT *
  FROM Northwind..Orders
 WHERE OrderID = @orderid Note that declaring a variable does not automatically assign some default value to that variable. This is different to some client programming languages. Declared variables which not yet have a value assigned are NULL.

]]>

Leave a comment

Your email address will not be published.