SQL Where statment, AND x IN (a, b, c)
Posted on 2011-03-01
So I'm guessing the solution to this is reasonably easy and I'm just missing something. I have a SQL query set up to output some data in a table, and everything works fine. I'm making another query that is similar except for one little difference. The where statement in the first query looks like so:
UpdateDate BETWEEN @StartDate AND @EndDate
AND LCCN IN (52015, 55215, 39010, 39100)
-- followed by
CASE WHEN LCCN = 52015 THEN 'Item A'
WHEN LCCN = 55215 THEN 'Item B'
WHEN LCCN = 39010 THEN 'Item C'
WHEN LCCN = 39100 THEN 'Item D'
The second query change will be to use ProductCode instead of LCCN, but ProductCode would also need to pull multiple numbers per group. So say the group by statement would look something like this (assuming this works)
CASE WHEN ProductCode between 1 and 10 THEN 'Item A'
WHEN ProductCode between 11 and 20 THEN 'Item B'
WHEN ProductCode between 21 and 30 'Item C'
WHEN ProductCode between 31 and 40 THEN 'Item D'
(As I said, I'm not sure that would work, but thats not my concern right now). The problem is I can't figure out how to do that in the Where statment. Something like
AND ProductCode IN (1 to 10, 11 to 20, 21 to 30, 31 to 40)
but I can't figure out what the correct way to do that would be (or for that matter if it is possible).
Thanks for the help let me know if more information is needed (sorry typed this up in a hurry).