• philip.cullingworth (11/3/2011)


    When running this in SQL2005 I get the following response (after answering the question)

    Msg 139, Level 15, State 1, Line 0

    Cannot assign a default value to a local variable.

    Msg 137, Level 15, State 2, Line 7

    Must declare the scalar variable "@CustAccount".

    You can not set the value of a variable at the same time as declaring it until SQL 2008.

    I had the answer correct, but I looked at the DECLARE statements again, read the question and noticed "...SQLServer2005 and greater..." The actual answer is "...error...assignment."

    "Prior to SQL Server 2008, assigning a default value (or initial value) to a local variable is not allowed; otherwise this error message will be encountered."