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.




Related Articles :

  • No Related Articles Found

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

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |