Sunday, February 26, 2012

Don't email report if no results from query

With an automated report (scheduling setup in report manager) is there a way to prevent the sending of an email if the report query has no results?Any ideas anyone?|||Sure. Rather than just creating a schedule, you'll need to do a data driven subscription which gets fired ON a schedule.

The data driven subscription will query another SQL Table which you will need to create and populate with data like who to send the report to (email), what report renderer to use (HTML? PDF? Excel?), what parameter values should be sent to the report for filtering purposes (someField = "SomeValue"), etc. You'll add one row per report which should get sent out.

When you create a data driven sub, the wizard will ask you WHERE it should get the info above from...you normally supply a basic SELECT statement that would select info from "your" table...In your scenario, you'd make the query a bit more complicated...Instead of JUST returning info from "your" table, you would also add some additional logic to check and see if the REPORT will actually return records. Here's a really, really ugly version of what I'm talkig about:

SELECT email,extensionType, myParameterValue from someTableICreated

WHERE exists(select * from a query that could be close to the one my report might use in it's data source..but this one should be quicker and return no rows if the report returns no rows )

Make sense?|||

FYI--This still e-mails a blank report if there are no records in the query, so I don't know what I'm missing.

Brian J. Matuschak
v-brmatu@.microsoft.com

No comments:

Post a Comment