Switch Statement within a SSRS SQL Expression

Hi, I am new to SQL expressions and having issues with this. I have a Search Field parameter where 1=Rental Date and 2 =Created Date. The user can select either value to base their date range from. I then have a From Date parameter and a To Date Parameter.

When the user select either Rental Date or Created Date, they then select the From and To Date ranges.

I tried this and I cannot get it to work:

Switch (Parameters!Search_Field.Value=1,"rai.chg_ci_tmsp", Parameters!Search_Field.Value=2,"frb.create_timestamp") & >= Parameters!FromDate.Value and <= Parameters!ToDate.Value

I have tried searching online and I am unable to find anything.

Is there someone that may have an idea on how to accomplish this?

Hi,

A more reliable way to handle this is by using the IIF function inside your query:

WHERE
IIF(@Search_Field = 1, rai.chg_ci_tmsp, frb.create_timestamp)
BETWEEN @FromDate AND @ToDate

This will dynamically choose either rai.chg_ci_tmsp or frb.create_timestamp based on the user’s selection and apply the BETWEEN condition correctly.