I have a report running on hour开发者_StackOverflowly basis checking for new orders. It's working great however, I would like to only send the report if there at least one order. If the report is empty - I don't want to send the report at all.
To extend this, I would like to only send the report if there new orders.
Ideas?
Just add a condition in your DDS query to check for the order time. If there are any orders in the past hour your query should return your result set otherwise return nothing.
For example, in your query add the following logic
DECLARE @HoursAgo int
SELECT Top 1 @HoursAgo = DateDiff('hh',getdate(), OrderTime)
FROM Orders
ORDER BY OrderTime DESC
In your query add the following clause
WHERE @HoursAgo > 0
You might also want to add extra checks to make sure the order is from the current day.
There is a property of the RDL dataset called "noRows" that can display a custom message if the dataset doesn't have any rows returned. It will still send the empty report, just with a special message.
If you want the subscription to not fire off the report then the only way I know of to do this is to check the row count of the select statement if your stored procedure and throw an error if the row count is zero. Not an elegant way to pull this off but it will not send the report because the error happens on the T-SQL side and SSRS won't be able to render the report.
declare @rows int
select @rows = -1
<select statement here>
select @rows = @@rowcount
if ( @rows < 1 )
begin
RAISERROR ('no rows returned', 11, 1 );
end
精彩评论