Cannot assign a default value to a local variable.

Error Message:
Msg 139, Level 15, State 1, Line n
Cannot assign a default value to a local variable.

Severity level:
15.

Description:
This error message appears when you try to assign a value to a variable when you declare it

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 = 10000

Remarks:
In contrast to some other programming languages does Transact-SQL not permit to assign a value to a variable at the time of declaration. Declaration and assignment are two distinct operations. To turn the above example into a valid one, you need to separate the declaration from the value assignment like this:
DECLARE @orderid INT
SET @orderid = 10000




Related Articles :

  • No Related Articles Found

2 Responses to “Cannot assign a default value to a local variable.”

  1. thanks,so helpfull:)

  2. Versions 2008 and newer DO support the assignment at declaration syntax.

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 |