I have created an SSRS report with three parameters - Two mandatory parameters and third which is a search parameter and also allow blank/Null value. I have made a dynamic query to handle three situations for a that search parameter
1.) Display records without passing value in Third parameter i.e. NULL value.
2.) Display records by passing single value in Third parameter.
3.) Display records by passing multiple values in Third parameter.
I am using below query:
IF (@Parameter3 = '')
BEGIN
EXEC('SELECT * FROM [TblName] with(nolock)
where [Col1] in ('+@Parameter1+') and [Col2] in ('+@Parameter2+')
')
END
ELSE
BEGIN
EXEC ('SELECT * FROM [TblName] with(nolock)
where [Col1] in ('+@Parameter1+') and [Col2] in ('+@Parameter2+') and [Col3] ('+@Parameter3+')
')
END
Now when I executes this query in sql server after passing my above three different scenerios it gives result acoording to parameters passed, But when I tried to add this in my Report Dataset it gives error--
Can a dynamic query be added into a dataset in SSRS?