Where Clause: Order of Precedence

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Where Clause: Order of Precedence

    Here's my WHERE clause on an SQL statement I wrote:

    WHERE blnLive = TRUE AND blnVacPromo = TRUE AND (dtToPost <= Now() AND
    dtToRemove > Now() )

    What I'm wondering is how can I use parentheses (sp?) to invoke this
    order or precedence?

    1.) Is blnLive equal to TRUE?
    2.) Is blnVacPromo equal to TRUE?
    3.) Is dtToPost less than or equal to Today?
    4.) Is dtToRemove greater than Today?

    I'm trying to optimize my WHERE clause as much as I can. I don't want
    the SQL engine to waste time trying to determine #2, #3, & #4 if #1
    isn't true. Or I don't want it to evaluate #3 & #4 if #1 is true and #2
    is false.

    Is order of precedence left to right? Inner parenthesis to outer
    parenthesis?

    Anyone have any insight on this?

    Thanks!
    GH Guest

  2. Similar Questions and Discussions

    1. ORDER BY clause in asp.net dataset
      I have an aspx page on which is a dataset created in DWMX. The sql query is described in the line CommandText='<%# 'SELECT * FROM booklist ' %>' I...
    2. Strange results of ORDER BY clause when item begins with slash orbackslash
      I am seeing some unexpected results for an ORDER BY in a query. It looks to me as if the sorting is confused about how to handle the slash or...
    3. Trouble with ORDER BY clause
      Hi all I'm not sure ASP is the problem, but my SQL statement seems fine to me. This works fine : strSQL = "SELECT .* FROM _RechPat INNER JOIN...
    4. order by precedence?
      I know how to use the order by, but wondered if there is an order of precedence in using it. Facts: hcounty is a county that someone puts in a...
    5. ORDER BY clause causes read-only recordset
      I have a website with some asp pages running off of a MS Sql db. For reasons that I can't explain, whenever querying the database with a SELECT...
  3. #2

    Default Re: Where Clause: Order of Precedence

    GH wrote:
    > Here's my WHERE clause on an SQL statement I wrote:
    >
    > WHERE blnLive = TRUE AND blnVacPromo = TRUE AND (dtToPost <= Now() AND
    > dtToRemove > Now() )
    >
    > What I'm wondering is how can I use parentheses (sp?) to invoke this
    > order or precedence?
    >
    > 1.) Is blnLive equal to TRUE?
    > 2.) Is blnVacPromo equal to TRUE?
    > 3.) Is dtToPost less than or equal to Today?
    > 4.) Is dtToRemove greater than Today?
    >
    > I'm trying to optimize my WHERE clause as much as I can. I don't want
    > the SQL engine to waste time trying to determine #2, #3, & #4 if #1
    > isn't true. Or I don't want it to evaluate #3 & #4 if #1 is true and
    > #2 is false.
    >
    > Is order of precedence left to right? Inner parenthesis to outer
    > parenthesis?
    >
    > Anyone have any insight on this?
    >
    > Thanks!
    Hmm, it looks like you're using Access. Please don't make us guess.

    Parentheses will not affect the evaluation of these criteria. ALL the
    criteria will be evaluated. Evaluation does not stop at the first criterion
    to return false. Parentheses will group boolean expressions, nothing more.
    Since all your operators are AND, parentheses will have no affect on this
    expression. Think of algebra: 1 + (2 + 3) = (1 + 2) + 3

    Grouping boolean expressions only affects expressions containing the OR
    operator. For example, this expression will evaluate to false:

    true_expression AND true_expression OR false_expression

    However, this will evaluate to true:

    true_expression AND (true_expression OR false_expression)

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows [MVP] Guest

  4. #3

    Default Re: Where Clause: Order of Precedence

    Bob Barrows [MVP] wrote:
    > GH wrote:
    >
    >>Here's my WHERE clause on an SQL statement I wrote:
    >>
    >>WHERE blnLive = TRUE AND blnVacPromo = TRUE AND (dtToPost <= Now() AND
    >>dtToRemove > Now() )
    >>
    >>What I'm wondering is how can I use parentheses (sp?) to invoke this
    >>order or precedence?
    >>
    >>1.) Is blnLive equal to TRUE?
    >>2.) Is blnVacPromo equal to TRUE?
    >>3.) Is dtToPost less than or equal to Today?
    >>4.) Is dtToRemove greater than Today?
    >>
    >>I'm trying to optimize my WHERE clause as much as I can. I don't want
    >>the SQL engine to waste time trying to determine #2, #3, & #4 if #1
    >>isn't true. Or I don't want it to evaluate #3 & #4 if #1 is true and
    >>#2 is false.
    >>
    >>Is order of precedence left to right? Inner parenthesis to outer
    >>parenthesis?
    >>
    >>Anyone have any insight on this?
    >>
    >>Thanks!
    >
    >
    > Hmm, it looks like you're using Access. Please don't make us guess.
    >
    > Parentheses will not affect the evaluation of these criteria. ALL the
    > criteria will be evaluated. Evaluation does not stop at the first criterion
    > to return false. Parentheses will group boolean expressions, nothing more.
    > Since all your operators are AND, parentheses will have no affect on this
    > expression. Think of algebra: 1 + (2 + 3) = (1 + 2) + 3
    >
    > Grouping boolean expressions only affects expressions containing the OR
    > operator. For example, this expression will evaluate to false:
    >
    > true_expression AND true_expression OR false_expression
    >
    > However, this will evaluate to true:
    >
    > true_expression AND (true_expression OR false_expression)
    >
    > Bob Barrows
    Sorry, yes, I'm using Access. That makes sense. Thanks for your help!

    Gabe

    GH Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139