-
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?
-
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.
-
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');"
-
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
-
Forum Rules