Sunday, June 13, 2021

SSRS - How to run SSRS report based on either of the 2 parameters

We need to write dataset query in IF ELSE manner with Parameter. Below is the example:

Suppose @QueryType is your input parameter:

/* Run first query*/

IF@QueryType = 1

BEGIN

       SELECT t1.col1, t1.col2, t1.col3, t1.col4, t1.col5, t3.id

       FROM t1

              JOIN t2

                     ON t1.id = t2.id

              JOIN t3

                     ON t2.wfid = t3.id

       WHERE t1.col1 = @Param

END

/* Run Second query*/

ELSEIF @QueryType = 2

BEGIN

       SELECT t1.col1, t1.col2, t1.col3, t1.col4, t1.col5, t3.id

       FROM t1

              JOIN t2 On t1.id = t2.id

              JOIN t3 On t2.wfid = t3.id

       WHERE t3.Id = @Param

END

No comments:

Post a Comment