Msg 139, Level 15, State 1, Line n
Cannot assign a default value to a local variable.
This error message appears when you try to assign a value to a variable when you declare it
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.
All versions of SQL Server.
DECLARE @orderid INT = 10000
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