not sure if it will work this way for an SQL Server database, but it will work on most ANSI compliant databases:
select item_no, count(distinct loc) from some_table
group by item_no
having count(distinct loc)<20
HTH
Question
I have an item database with an item number and locations. There are supposed to be 20 locations for each item. How do I find all the items that do not have all locations from 01 - 20
item_no loc
1 01
2 02
I tried
select distinct item_no from iminvloc_sql where loc not in (00,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20)
But that didn't seem to work
Solution
not sure if it will work this way for an SQL Server database, but it will work on most ANSI compliant databases:
select item_no, count(distinct loc) from some_table
group by item_no
having count(distinct loc)<20
HTH