Use what I've called the "coalesce trick". Use a parameter = NULL as a "don't care" value.
Your WHERE expression then becomes (e.g.):
Code:
... WHERE CategoryID = COALESCE(@Category, CategoryID) ...
When the parameter @Category is NULL, then the coalesce function returns the value of the 'CategoryID' column. Comparing it to itself is always true, so this is a No-op, i.e "don't care" what the 'Category' value is. When @Category is not NULL, then the compare is to the parameter value.
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com