DELETE FROM tblArtworkApprovalUsers
WHERE (userID NOT IN (@UserIDList)) AND (approvalID =
(SELECT ID
FROM tblArtworkApprovals
WHERE (templateID = @TemplateID)))
This is in my table adapter. @UserIDList needs to accept something like:
2,44,12,70
How can I make this query accept that string?
NOT IN <expr>requires an expression and not a string. So if you are passing the parameter and not constructing the SQL dynamically this cannot be done.Alternative is to create the SQL dynamically (while being aware of SQL Injection):
UPDATE
Craig pointed to a better solution here which does not provide much better performance (since parameters are variable and query plan does not get cached unless it is exactly the same) but help with SQL injection attack:
Parameterize an SQL IN clause