T-SQL Syntax Bug

  • I know I typed this wrong during testing but I didn't get an error.

    I was consolidating a stack of IF .. OR IF .. into a IN clause

    IN ('4897','4898','4899','4896','4424','4425','4426','4434')

    Works Just fine

    IN ('4897' '4898' '4899' '4896' '4424' '4425' '4426' '4434')

    Produces a Syntax error (there is a space between each entry)

    IN ('4897''4898''4899''4896''4424''4425''4426''4434')

    Runs just fine, but only uses the first ('4897') entry. No space between each entry.

    Just something to watch out for.

    KlK, MCSE


    KlK

  • Kevin,

    The last example won't throw an error because it's a valid SQL string. The lack of intervening spaces means that the doubled quotes are interpreted as single quotes.

    If you run:

     
    
    select '4897''4898''4899''4896''4424''4425''4426''4434'

    You get:

     
    
    4897'4898'4899'4896'4424'4425'4426'4434

    Cheers,

    - Mark


    Cheers,
    - Mark

Viewing 2 posts - 1 through 1 (of 1 total)

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