Conditional reporting in SSRS

你说的曾经没有我的故事 提交于 2019-12-08 12:10:09

问题


I have a SSRS 2008 sever running in native mode. I'm trying to figure out if the following is possible and if so, how to do it. I would like to have a scheduled subscription that only generates a report when some condition is satisfied. The most natural way to express the condition for me would be if a particular query comes back with data. Is this possible?

So basically I would check the the DB on a regular schedule and if some data is there (like in an error log) send an email about it.

After some more research I found this link: http://blogs.msdn.com/b/bimusings/archive/2005/07/29/445080.aspx where in the comments people offer the following trick:

IF NOT EXISTS ( SELECT * FROM ....)

RAISEERROR('no records found,'16,1

ELSE

SELECT * FROM ....

I can use this to either produce an email to send to or throw an error. The problem is that my reports are wrapped in stored procedures and you can not use IF NOT EXISTS with store procs. Does any one have any recommendations on how to check if a stored procedure returned rows without putting it into a temp table or executing it an looking at @@rowcout? The last one is not good for me because I can't have the output of the procedure also returned along with the email.


回答1:


You are looking for Data-Driven Subscriptions. From that MSDN documentation:

Reporting Services provides data-driven subscriptions so that you can customize the distribution of a report based on dynamic subscriber data. Data-driven subscriptions are intended for the following kinds of scenarios:

• Distributing reports to a large recipient pool whose membership may change from one distribution to the next. For example, distribute a monthly report to all current customers.

• Distributing reports to a specific group of recipients based on predefined criteria. For example, send a sales performance report to the top ten sales managers in an organization.

Not all editions of SSRS support data-driven subscriptions, so be sure to check if your version does.

I haven't worked much with it, but AFAIK it should satisfy your requirements. From a related / relvant MSDN page:

Use data-driven subscriptions to customize report output, delivery options, and report parameter settings at run time. The subscription uses a query to get input values from a data source at run time. You can use data-driven subscriptions to perform a mail-merge operation that sends a report to a list of subscribers that is determined at the time the subscription is processed.

It seems that this is what you're after.




回答2:


You can actually trigger SSRS reports using a TSQL command. I have a script that is scheduled to run regularly and does some SQL twiddling to decide if it should run a particular SSRS report or not. That should do the trick for you. What you do is fine the id for the report and then execute it like any other job - I suggest you look at a scheduled SSRS report to see what the parameters look like when in the DB so you can call it correctly.



来源:https://stackoverflow.com/questions/16359141/conditional-reporting-in-ssrs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!