I think the 'IN' operator complicates things a bit. If we ignore that for the moment, the usual 'trick' for this sort of thing is to define a parameter which if it has a value, then the query is to use that value in a WHERE clause; if it doesn't, i.e. the parameter value is NULL, then the parameter means "don't care" - you'll take any value in that column. So in your example a NULL value would mean "all departments"
You use the COALESCE function, as:
Code:
... WHERE source_cd = COALESCE(@parameter,source_cd) ...
If the parameter is not NULL, then 'source_cd' is compared to the parameter's value. If the parameter is NULL, then 'source_cd' is compared to itself, which is always TRUE, which results in all rows being selected.
I'm not sure how you are handling the IN clause via parameters...
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com