Tuesday, June 29, 2010 8:04 PM
I'm using BIDS in Visual Studio 2008 against a 2008 R2 Reporting Services Server.
I have a requirement to only send out a report if there are rows in the data. The customer said I could also send out an email that said there is data or there is not.
I cant figure out how to do this through the dashboard. I cant put an expression in the email subject . If I could that would probably sort it. I could just do = count(field, dataset) in the subject.
The other solution I have come up with is, via BIDS, to have the report page say "There were ZERO records for this report query" (and only that) if there is no data. I'd then have SiteScope query the snapshot URL, grep for the string, and then send out a custom email saying "No Data Today"....or vice versa.
The next thing I will try is to just do the same thing via c# .NET that the sitescope program is doing.
I've also just in the last few minutes browsed the delivery extensions, but, at this point. I'm not sure that it will do what I want.
The other challenge here is that if I use Sitescope, I have to correctly anticipate the snapshot timestamp.......that looks like its going to be problematic. So I'll probably have to do it in .NET run the query from there, then send the email from there AND, darn, I'll probably still have to, somehow, programattically figure out the snapshot time so that I can put the link to the snapshot in the email. It'd be far easier to just access "the most recent" snapshot than to use that timestamp url syntax.
It'd be a lot easier if there were built in options for doing this or that (in terms of delivery) based on the report output......but, so far, i have not found anything like this.
Tuesday, June 29, 2010 8:10 PM
When you create a subscription there will be a Job created under SQL Server Agent. The Job will be executing the ReportServer.dbo.AddEvent stored procedure. You can edit the Job Step to have a condition to execute the procedure. So, if you include a condition saying that if there is no. of record is greater than one then execute the procedure. Hope this helps.
You can refer the following link :
Tuesday, June 29, 2010 8:34 PM
Thanks, the only challenge here is that I feel better, even when I code perfectly!, if the user is receiving something either way. So IF , there is data, generate the email as normal. IF there is NO data then send an email with the subject "NO SOUP FOR YOU!" (or whatever). This way I'm not in the condition of something going wrong and I get the call from the user saying they have not received the report in 2 months and just wanted to check in...........then I find something screwed up in an unanticipated way.
However, I'm new to this Reporting Services stuff and had no idea about the ReportServer.dbo.AddEvent stored procedure. So thanks! Thats very helpful. I'll use your link to see if i can get some feedback in to MS somewhere on this point. I think it should be a standard offering, I mean users only want to know if something is amiss.........they dont want to pore over the same boring data every day. So "Conditional Reporting/Reporting Delivery" I think there is a world of opportunity here.
Tuesday, June 29, 2010 8:46 PMAND, know any good books on programming Reporting Services using C# .NET? I have Safari Premium.
Thursday, July 01, 2010 9:34 AMModerator
SQL Server Reporting Services has ability to use dynamic subscription data that is retrieved from an external data source at run time.
In this case, we can use the dynamic query to check if there has data. If not, we don't provider the recipients. Then the report won't be sent.
For more information about Data-Driven subscription, please see:
In addition, to learn more about developing in SQL Server Reporting Services, I would suggest you starting from here:
If you have any more questions, please feel free to ask.
Jin Chen - MSFT
- Marked As Answer by Challen FuModerator Friday, July 09, 2010 2:33 AM
Wednesday, December 15, 2010 6:06 PM
What I do is setup a data-driven subscription that will only return email addresses to the subscribers if there is data returned for the query.
You could code your query into a parameterised stored procedure (the source of the report which you have just built and want to have an automatic email for) which you then use in another stored procedure to give a list of emails (if there is any data returned from you main report stored procedure).
INSERT INTO @tmpTable -- create above in proc
EXEC dbo.usp_R001_ReportData 'param1','param2', 1000
FROM udf_ParameterStringToTable2( @EmailAddress, ';') -- multi-value string to table parser -- google for code or see below.
WHERE EXISTS (SELECT TOP 1 field1 FROM @tmpTable);
This will only return the addresses where there is data returned for the query.
Cons: Runs data query twice - once in the email check and then once for the report.
Pros: no agent job hacking, no .Net, pure SQL.
, @sep char(1)
@tbl TABLE (
-- start by creating a temp numbers table,
-- simply a list of numbers from 1 to 5,000 (actually 2 12)
DECLARE @tmpNums AS TABLE
(n int not null)
DECLARE @max as int
, @rc as int
SET @max = 5000
SET @rc = 1
INSERT INTO @tmpNums VALUES(1)
WHILE @rc * 2 <= @max
insert into @tmpNums
select n + @rc
set @rc = @rc * 2
INSERT INTO @Tbl
substring(@string, n, charindex(@sep, @string + @sep, n) - n) as element
WHERE n <= DATALENGTH(@string + @sep) + 1
and substring(@sep + @string, n, 1) = @sep