Here's another Where Clause question.
AND a.AccountID IN (COALESCE(@AccountID, (SELECT Items FROM dbo.SplitIDs(@AccountIDs)), a.AccountID))
This line does not work because you can't use a SELECT query in an expression that returns more than one value. The problem is that a single ID integer value may be passed in, or a string of several comma separated IDs may be passed (which is split by a UDF that returns a table of integers), or possibly no ID is passed in at all, in which case we only want to search on other possible parameters and not have to worry about the ID field at all. Can this be done in a single procedure or do I just need to write two procedures, one for passing in integers and one for passing in strings? (One procedure would just make for easier maintenance.)