I have a stored procedure and its purpose is to query a table for rows that do no match the declared LocID
. However, what I am trying to do now is the best method to filter out my data based on rows that:
- Do not match the
LocID
- Do not match the
ZipCode
from the declaredLocID
value
Code:
DECLARE @LocID
SELECT ZipCode
,[Description] = ZipCode + ' - ' + Description
FROM LocMap
WHERE LocID <> @LocID
Here is a quick layout of table named LocMap
.
LocID | ZipCode | Description
----------------------------------
100 | 91012 | Magical Sky
100 | 91013 | Dream Land
101 | 91012 | Blue Ocean
102 | 91012 | Gray Screen
104 | 91014 | Limit Break
108 | 91016 | Magic Hammer
The result is returned in JSON format in order to populate into the second dropdown field on a form based on the LocID
the user selects from the first dropdown field. So for example, if user selects LocID = 100
from the first dropdown, then the stored procedure will execute the query and only return ZipCodes
that are NOT in LocID = 100
. In this case, the rows with ZipCodes
91014 and 91016 would return in the second dropdown.
What would be the best way to perform this? Would this be something I need to do through a subquery in the stored procedure? I feel like I'm over thinking this.