I have a problem which I think relates to having a multiple value parameter.
In my TblActivity there are two fields TblActivity.ActivityServActId
and TblActivity.ActivityContractId
which I want to include in my WHERE statement.
Filtering by these is optional. If the user selects 'Yes' for the parameter @YESNOActivity
, then I want to filter the query looking for rows where TblActivity.ActivityServActId
matches one of the options in the parameter @ServiceActivity
.
The same goes for the @YESNOContract
, TblActivity.ActivityContractId
and @Contract
respectively
I managed to get to this:
WHERE
(CASE WHEN @YESNOActivity = 'Yes' THEN TblActivity.ActivityServActId ELSE 0 END)
IN (CASE WHEN @YESNOActivity = 'Yes' THEN @ServiceActivity ELSE 0 END)
AND (CASE WHEN @YESNOContract = 'Yes' THEN TblActivity.ActivityContractId ELSE 0 END)
IN (CASE WHEN @YESNOContract = 'Yes' THEN @Contract ELSE 0 END)
However, although this code works fine if there is only one value selected in the parameter @ServiceActivity
or @Contract
, as soon as I have more than one value in these parameters, I get the error:
Incorrect syntax near ','.
Query execution failed for dataset 'Activity'. (rsErrorExecutingCommand)
An error has occurred during report processing. (rsProcessingAborted)
Can anyone see what I'm doing wrong? I could understand it if I had an = instead of IN in the WHERE statement but can't figure this one out.
Using SQL Server 2008 and SSRS 2008-r2