Consulting

Results 1 to 4 of 4

Thread: SQL query using where with multiple criterias

  1. #1

    SQL query using where with multiple criterias

    I'm able to connect and retreive data using the SQL string below BUT it seems the WHERE isn't working properly. hdr_RD section

    SQL = "SELECT [hdr11], [hdr31], [hdr32], [hdr33], [hdr34] FROM " & strTable & " WHERE [hdr_RD] Like 'New' OR [hdr_RD] Like 'Hold' AND [nhr_ISD_by] Like 'ES-8000-00' AND [ndr_TP] Like 'FV' OR [ndr_TP] = 'LV' OR [ndr_TP] = 'PV' OR [ndr_TP] = 'TV'"

    Look like a typo error or something missing?

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    782
    Location
    WHERE [hdr_RD] Like 'New*'
    WHERE [hdr_RD] Like '*New'
    WHERE [hdr_RD] Like '*New*'

    Depends on your string, pick convention from above.
    you may need to use % instead of *

    Also, I would use brackets as well.... if you don't i think you may run into unexpected results due to logic of AND and OR.

  3. #3
    you can also do like this:

    SQL = "SELECT [hdr11], [hdr31], [hdr32], [hdr33], [hdr34] FROM " & strTable & _
    " WHERE " & _
    "[hdr_RD] IN ('New', 'Hold') AND " &
    "[nhr_ISD_by] = 'ES-8000-00' AND " & _
    "[ndr_TP] IN ('FV', 'LV', 'PV', 'TV');"

  4. #4
    arnelgp: your solution is the perfect fit. I was unaware of this way to combine several criterias. Big Thanks!!!

    JKwan: I tried those but it wasn't the solution. Thanks!

Posting Permissions

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