SQL NOT IN clause rewrite with Parameters help
Posted on 2010-09-17
Hi... I am trying to rewrite a query and need your help. Essentially, this is the query:
SELECT FirstName, LastName
FROM nameTable nt
JOIN userTable ut ON (ut.userId = nt.userId)
WHERE ut.userId NOT IN (SELECT userId FROM badUsers WHERE denyUser = ?)
I need to rewrite the query to allow for Parameterized SQL in ASP. Currently the above query gives an error if I try to pass it a parameter (Parameters cannot be used in statements with a sub-query). I would like to have it rewritten as maybe a JOIN such that it accepts a parameter and produces the same results.
The goal of the query is to make sure the users are NOT in the subset of bad users that have denyUser = TRUE or FALSE. Obviously this is not the actual query and yes, I did make this up on the fly. The original query is dynamically built based on the information passed to the script so it's difficult to supply an actual example due to it's dynamic nature.