The variable name ‘%.*ls’ has already been declared. Variable names must be unique within a query batch or stored procedure.

Error Message:
Server: Msg 134, Level 15, State 1, Line n
The variable name ‘%.*ls’ has already been declared. Variable names must be unique within a query batch or stored procedure.

Severity level:
15.

Description:
This error message appears when you try to declare a variable that has already been declared.

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):
DECLARE @orderID INT
SET @orderID = 10289
SELECT *
  FROM Northwind.dbo.Orders
 WHERE OrderID = @orderID
DECLARE @orderID BIGINT

Remarks:
The above example tries the declare the variable @orderID in the last line, although it has already been declared in the first line of the batch. You can circumvent this error message by placing a GO between the SELECT and the following DECLARE. By doing so the whole batch becomes syntactically valid and finishes without any error. However you should carefully check on the logical level if the second DECLARE is necessary at all.




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 |