The smartest way to do "multiple or" with SQL?

Jaymond Flurrie

Well-known Member
Joined
Sep 22, 2008
Messages
921
Office Version
  1. 365
Platform
  1. Windows
Let's say we have 51 categories for Area, like, say, the states of USA. Now my programs wants to select all the people that lives in states that my user selected. Let's say those are "AR", "CO", "CA", "WY" or "HI". So far this is simple, right?

Now the part where I stick my finger into my mouth is that how do I do this in an SQL query? Hardcoding 51 OR-categories sounds more than stupid, and in my real problem I can't even know if there 1, 5, 15 or 51 of those "OR-categories".

Do we have some "is on the list"-operator in SQL? Can I just pass a typical VBA-array there?
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi

You can use the IN operator e.g.

SELECT * FROM MYTABLE WHERE STATE IN ("AR", "CO", "CA", "WY","HI")


HTH
DK
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,520
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top