Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop empty reports from being sent in SSRS 2008 R2 Data-Driven Subscription

I am scheduling some reports by using data driven subscription in SSRS 2008 R2.

Regardless of whether the generated report is empty or not, reports are still sent to recipients. This has been a common problem for long time, and honestly, the suggestions I have seen on the forums did not quite work out.

One of the suggestions, I tried, was that I have created a hidden parameter and set it to a field on the main dataset in default values tab. It throws error if the report is empty and report is generated if there is some data to show in report designer. However, when I schedule this report, it asks me to provide default value and I cannot finish scheduler wizard without providing it. If I provide any default value, the empty reports are still sent. But unlike this, an error is supposed to be thrown for empty reports and they should not be sent.

has anyone used this method before? if so, could you tell me what I am missing here please?

I was just wondering whether you guys have an ideal solution for this issue.

Many thanks for your help.

Regards

like image 234
AnarchistGeek Avatar asked Dec 19 '11 10:12

AnarchistGeek


People also ask

What is difference between standard and data-driven subscription in SSRS?

A standard subscription consists of static values that cannot be varied during subscription processing. Data-driven subscriptions get subscription information at run time by querying an external data source that provides values used to specify a recipient, report parameters, or application format.

What is data-driven subscription in SSRS?

A data-driven subscription provides a way to use dynamic subscription data that is retrieved from an external data source at run time. A data-driven subscription can also use static text and default values that you specify when the subscription is defined.

Can we send SSRS report as email attachment?

No, it's not possible to attach another file with an e-mail subscription from SSRS.


2 Answers

Here is my workaround: Retrieve your data via a stored procedure and put the following code in the end

IF @@ROWCOUNT = 0 RAISERROR('No data', 16, 1)

Check Russell Christopher's article and comments for more details. What surprise me is it has been 6 years and MS just can't come out a solution for this :3

like image 58
walterhuang Avatar answered Sep 20 '22 00:09

walterhuang


Something I have found to work that is very easy to implement is to simply include an extra field in your query that divides by the row count. If the count is zero then you get a divide by zero error and the email is not sent; if the count is at least one then the report runs fine and the email goes out.

SELECT 
  [table].[id]
  ,(1/COUNT(id))
FROM [table]
WHERE [table].[id] > @Parameter

One note about this technique is that it does add some extra overhead so it may not be appropriate if you expect the possibility of very large data sets.

like image 25
Wayne Avatar answered Sep 24 '22 00:09

Wayne