Where conditions

  • Evgeny Garaev

    SSCertifiable

    Points: 6742

    Comments posted to this topic are about the item Where conditions

  • HappyGeek

    SSCoach

    Points: 18684

    Nice simple question thanks Evgeny.

    ...

  • Aleksl-294755

    Hall of Fame

    Points: 3514

    Nice easy question, good practice - use parenthesis. Thanks.

  • Aaron N. Cutshall

    SSCrazy Eights

    Points: 8812

    Funny, I was actually glad to get this one wrong!  I had always assumed that there was no order of logical precedence and therefore always preached using parenthesis correctly.  I came across an instance very much like the example and I always wondered how it just happened to produce the correct results.  Now I know, but I sure wouldn't want to rely on it!!

  • lmalatesta

    SSChasing Mays

    Points: 637

    Aaron N. Cutshall - Monday, April 2, 2018 7:38 AM

    I had always assumed that there was no order of logical precedence and therefore always preached using parenthesis correctly.

    Style wise, it's always a good idea to use parentheses to disambiguate. But AND being "stickier" than OR is a pretty straightforward order of operation. That order holds in most programming languages and formal logics. There are some exceptions out there but in SQL it's well defined.

  • SADSAC

    SSCrazy

    Points: 2078

    Nice one, thanks Evgeny

  • Stewart "Arturius" Campbell

    SSC Guru

    Points: 71907

    Aaron N. Cutshall - Monday, April 2, 2018 7:38 AM

    Funny, I was actually glad to get this one wrong!  I had always assumed that there was no order of logical precedence and therefore always preached using parenthesis correctly.  I came across an instance very much like the example and I always wondered how it just happened to produce the correct results.  Now I know, but I sure wouldn't want to rely on it!!

    The login is well set in languages like T-SQL and C#.
    However, applying parenthesis is always a good idea, making it easier to read and to transport to other languages

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

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

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