简体   繁体   中英

SSRS 2008: Execute dataset on boolean value

Currently using a Boolean parameter and some custom code to check at least one of the user accessible parameters has data. If this Boolean is true I need to run a stored procedure on my one dataset otherwise I want it to do nothing as I have a textbox for an error with visibility set to the Boolean's value.

具有默认值的布尔参数

自定义代码

=Code.NoParameters(Parameters!StartDate.Value,Parameters!EndDate.Value,Parameters!ClientCode.Value(0))

Function NoParameters(StartDate as DateTime, EndDate as DateTime, ClientCode as String) As Boolean
Dim RetValue as Boolean
RetValue = "False"
If(StartDate = Nothing And EndDate = Nothing And ClientCode = Nothing)
RetValue = "True"
Else
RetValue = "False"
End If
Return RetValue
End Function

I've tried a few variations of

If IsEmpty = False EXEC sp_grand_smslog_processing

and also

iif (Parameters!IsEmpty.Value = False, "sp_grand_smslog_processing" , " ")

This is the last thing I need to be able to publish this report which I've been working on for a whole week. Please Halp!

The problem you have is that SSRS expects a dataset to always have the same data structure returned, if you do not execute the query then nothing is returned when what you actually need is an empty dataset.

2 basic ways of doing this.

First you could modify the stored proc, (you may have to pass it an additional parameter which prevents execution) and then just return no results.

However, I would probably avoid that as it means that your stored proc has to be modified and you might not want to do that, and it also means you still end up running the stored proc.

I would change my dataset query to be something along these lines...

DECLARE @SpResults TABLE(myCol1 int, myCol2 int etc....) -- <<-- This should match the output form your stored proc exactly.

IF @RunThis = 1 -- execute the SP and dump results into @SpResults table
    BEGIN
        INSERT INTO @SpResults
          EXEC myStoredProc
    END
-- finally return the table contents
-- The @RunTHis = 0 then the table will be empty, but still valid
SELECT * FROM @SpResults

Note: You could swap out the table variable for a temp table depending on the size of the results etc, but the principle is exactly the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM