Thread: SQL Query

    #1
  1. No Profile Picture
    Contributing User
    ASP Good Citizen (1000 - 1499 posts)

    Join Date
    Feb 2005
    Posts
    1,283
    Rep Power
    36

    SQL Query


    I have the below code that is running a query. IT WORKS great...I have to modify it an confused on the syntax...
    I need to add another varRequestType...

    So the query will read: WHERE varStatus = Planned AND varREquestType1 = Web REquestor OR varRequestType2 = Mobile

    Dim varRequestType1, varRequestType2, varStatus
    varRequestType1 = "Web Requestor"
    varRequestType2 = "Mobile"
    varStatus = "Planned"
    Dim myConn, Recordset,SQLQuery

    SQLQuery = "SELECT * FROM MainGeneral WHERE Requestor = '" & varRequestType1 & "' AND Status = '" & varStatus & "' "


    ???? Do I need () to encapsulate the OR statement from the AND Statement

    SQLQuery = "SELECT * FROM MainGeneral WHERE Status = '" & varStatus & "' AND Requestor = '" & varRequestType1 & "' OR Requestor = '" & varRequestType2 & "' "
  2. #2
  3. No Profile Picture
    Contributing User
    ASP Good Citizen (1000 - 1499 posts)

    Join Date
    Feb 2005
    Posts
    1,283
    Rep Power
    36
    This worked

    SQLQuery = "SELECT * FROM MainGeneral WHERE Status = '" & varStatus & "' AND Requestor = '" & varRequestType1 & "' OR Requestor = '" & varRequestType2 & "' "
  4. #3
  5. Moderator
    ASP Super Genius (4500 - 4999 posts)

    Join Date
    Apr 2009
    Location
    The Great Land
    Posts
    4,621
    Rep Power
    650
    Do you need some parens in there like:

    SQLQuery = "SELECT * FROM MainGeneral WHERE Status = '" & varStatus & "' AND (Requestor = '" & varRequestType1 & "' OR Requestor = '" & varRequestType2 & "')"
    I like to know if my suggestion helped you. One way to let me know is by clicking star at bottom left corner of post.
    Debug!Debug!Debug!http://www.cpearson.com/excel/debug.htm

Similar Threads

  1. Replies: 0
    Last Post: August 26th, 2008, 05:45 AM
  2. Replies: 14
    Last Post: February 7th, 2007, 08:31 AM
  3. Replies: 9
    Last Post: March 10th, 2005, 12:28 AM
  4. Replies: 1
    Last Post: October 20th, 2004, 04:50 AM
  5. MAke query and Select Query give diff results
    By AnalystDP in forum Microsoft Access Help
    Replies: 2
    Last Post: June 24th, 2004, 02:36 PM

IMN logo majestic logo threadwatch logo seochat tools logo