I am working on a stored procedure to get accounts for a case. If the @accounts
parameter is NULL
, I want to get all the accounts for the case. If @accounts
is NOT NULL
, then it will be a comma separated string of accountid's. I would like to have a single where clause that can handle this. Something that says if @accounts
is NULL
then grab all the accounts for the case. Otherwise, use the @accounts
parameter and grab the accounts with the account id's specified. I would like to avoid a big IF
statement that would require me to have the query twice with 2 different WHERE
clauses.
DECLARE @caseId BIGINT,
DECLARE @accounts VARCHAR(255)
SELECT TOP 1 @userId = userId FROM TblTraceCur t
WHERE caseId = @caseid
ORDER BY processDate DESC
SELECT
.... (select logic) ...
WHERE
t.caseId = @caseID AND
t.userId = @userId AND
t.shortStock = 0 AND
... (where I need the new logic) ...
order by t.tracln ASC
Thanks a lot!