Error 137 - you must declare the scalar variable

  • Hi,

    I'm running a script against 16 registered servers (6 SQL 2000, 4 SQL 2005, 6 SQL 2008R2) within the same connection.

    It works well, except for 2 of 6 the SQL 2008R2.

    I receive the error: Error 137 - you must declare the scalar variable.

    The script starts like that:

    Declare @datefull datetime

    Declare @datelog datetime

    Set @datefull = '01/05/13 23:12:00.500'

    Set @datelog = '28/09/13 14:05:23.100'

    Select .....

    From ....

    GO

    I can't understand why those 2 SQL 2008R2 return this error, as it is the same script for all registered servers.

    Could it be an Instance configuration ?

    Thanks,

    Dok

  • Without seeing the rest of the proc, error line number, etc, it's difficult to tell but it could be an artifact later in the code caused by the date format or language settings and the fact that it appears that your dates are in the dd/mm/yyyy format. Total shot in the dark, though.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • dokledon (8/2/2013)


    Hi,

    I'm running a script against 16 registered servers (6 SQL 2000, 4 SQL 2005, 6 SQL 2008R2) within the same connection.

    It works well, except for 2 of 6 the SQL 2008R2.

    I receive the error: Error 137 - you must declare the scalar variable.

    The script starts like that:

    Declare @datefull datetime

    Declare @datelog datetime

    Set @datefull = '01/05/13 23:12:00.500'

    Set @datelog = '28/09/13 14:05:23.100'

    Select .....

    From ....

    GO

    I can't understand why those 2 SQL 2008R2 return this error, as it is the same script for all registered servers.

    Could it be an Instance configuration ?

    Thanks,

    Dok

    You could also doublecheck that these two servers don't have one of those "case sensitive" collations. If it had a case sensitive collation and you aren't consistant with your naming of variables (the declaration has all lowercase and subsequent use of that variable maybe has an uppercase spelling), this could lead to these specific servers complaining while others successfully run.

    Just a possibility you might want to eliminate!

  • Thanks to Jeff and Patrick for their answers.

    It was indeed a collation problem, as one of the variable was using Upper case and was called with Lower case.

    Dok.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply