Using both AND OR on the query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rjlorenzo
    New Member
    • Oct 2008
    • 16

    Using both AND OR on the query

    Good Day,

    I'm trying to display record using a query below.
    Code:
    if sagent = "CARE" AND FDATE <>"" AND TDATE <>"" then
    
    SQL = "SELECT * FROM WEB_PRODUCTIVITYDONE WHERE PROD_USER ='lckatigbak' OR PROD_USER ='jbmarquez' AND PROD_ENTERED BETWEEN #" & fdate & "# and #" & tdate & "#;"
    
    end if
    What i'm trying to do is when i select CARE and enter FROM DATE and TO DATE is should display all the record that the user is under "lckatigbak " and jbmarquez" and between from date and to date.
    Base on the query above it just display the all the record under those agent regardless of date.
    The question is, It is possible to use OR AND at the same time on the query. is there any other way i could do it.

    thank you in advance.
    RJ Lorenzo
    Last edited by JamieHowarth0; Oct 18 '08, 09:02 PM. Reason: Added code tags
  • JamieHowarth0
    Recognized Expert Contributor
    • May 2007
    • 537

    #2
    Hi there,

    Firstly, please use [ code] and [/ code] tags around your code.

    Second you could try using an IN clause:

    Code:
    if sagent = "CARE" AND FDATE <>"" AND TDATE <>"" then
     
    SQL = "SELECT * FROM WEB_PRODUCTIVITYDONE WHERE PROD_USER IN ('lckatigbak','jbmarquez') AND PROD_ENTERED BETWEEN #" & fdate & "# and #" & tdate & "#;"
     
    end if
    Hope this helps.

    codegecko

    Comment

    • iam_clint
      Recognized Expert Top Contributor
      • Jul 2006
      • 1207

      #3
      you can use parands to separate these things...

      where (blah = blah or blah = 2 or blah = 3) and (cat=1 or cat=2)
      Code:
      SQL = "SELECT * FROM WEB_PRODUCTIVITYDONE WHERE (PROD_USER ='lckatigbak' OR PROD_USER ='jbmarquez') AND (PROD_ENTERED BETWEEN #" & fdate & "# and #" & tdate & "#);"

      Comment

      Working...