views:

61

answers:

2

I have a Rate column in one of my SQL Table where Data is stored. The data in the rate column , is coming thro an Stored proc. In that existing stored proc, I found the condition

      BEGIN
        IF     @taxPrd <  '07/01/2000' OR 
               @taxPrd >= '11/01/2001' AND @taxPrd <  '04/01/2003' 

          BEGIN

I changed it to ...so as to make it true for ALL periods after sep-1/09

      BEGIN
        IF     @taxPrd <  '07/01/2000' OR 
            ( @taxPrd >= '11/01/2001' AND @taxPrd <  '04/01/2003' ) OR
               @taxPrd >= '09/01/2009'

          BEGIN

hence now the rate is valid for

              all less than Jul2000 OR
              all in between Nov2001 and Apr2003 OR
               all more than Sep2009

is the placements of brackets correct?

+1  A: 

Your parentheses are placed correctly for what you want to achieve.

Philippe Leybaert
thanks Phillippe!I have one further query there is an related IF condition just above the ABove condition IF @taxPrd >= '06/01/2005' BEGIN ....I changed it to IF @taxPrd >= '06/01/2005' OR @taxPrd < '09/01/2009' BEGIN ....I did not place brackets in this case.should i place brackets whne there are two conditions only?
vas
+2  A: 

In your case the brackets are not necessary, (although I'd leave them there for clarity) because the boolean Operator AND takes precedence over the OR operator. i.e., whenever there is a mixture of ORs and ANDs in a predicate, the ANDs are processed first, and then the resulting expression (with ORs in it ) is processed.

for example

 A Or B Or C And D Or E And F And G Or H

would be processed as

 A Or B Or (C And D) Or (E And F And G) Or H
              \  /          \    /   
               ||             ||                                
 A Or B Or    C&D   Or      E&F&G       Or H
Charles Bretana