Mr. & Mrs.Smith!

  • Comments posted to this topic are about the item Mr. & Mrs.Smith!

  • Aha... This one's easy.

    SQL DBA.

  • This question reminded me of something that I've never understood. You would get the same answer to the question if the where statement looked like this:

    where lastname like 'Smith%'

    and firstname like '%a%'

    and ID in ()

    that is, without the parentheses. What I don't understand is why people write code with parentheses when all the conditions are equivalent in evaluation. If all you have are ANDs or all you have are ORs, what purpose is there to putting parentheses around the individual conditions? I was taught that you only needed parentheses when you were combining ANDs and ORs. Is that true, or do all these what seem to be extra parentheses have some value?

    Thanks,

    Mattie

  • I agreed with you. I do not like unneeded parenthesis.

  • Carlo Romagnano (5/2/2009)


    I agreed with you. I do not like unneeded parenthesis.

    I agree too, about not liking unnecessary parentheses. But I can hazard a guess as to why people do it: perhaps they first learned a language where parentheses around conditionals were mandatory (if X then Y not allowed, it has to be of (X) then Y) and/or they used languages where words like "and" and "or" were heavily overloaded ( X = a or b might mean either X = (a or b) or (X = a) or b depending on the types of X, a and b, and could actually be ambiguous for some type combinations) amnd got into the habit os using brackets all the time.

    Different point: this question points up one of the stupidities of SQL: () represents a set of columns/values, except in the single case where is the empty list, in which case using it to represent a set will give you a syntax error. That's the sort of inconsistency that really irritates me (as a former language designer) - it makes the syntax slightly harder to analyse so that writing a compiler/tokenizer/interpreter is harder; and it makes the language slightly more difficult to learn; and (this is the crunch point) it sometimes makes the language quite a lot harder to generate dynamically.

    Tom

  • EASY ONE!!

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

Viewing 6 posts - 1 through 5 (of 5 total)

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