SQL Server Reporting Services 2005 - How to Handle Empty Reports - sql

I was wondering if it is possible to not attach Excel sheet if it is empty, and maybe write a different comment in the email if empty.
When I go to report delivery options, there's no such configuration.
Edit: I'm running SQL Server Reporting Services 2005.
Some possible workarounds as mentioned below:
MSDN: Reporting Services Extensions
NoRows and NoRowsMessage properties
I should look into these things.

I believe the answer is no, at least not out of the box. It shouldn't be difficult to write your own delivery extension given the printing delivery extension sample included in RS.

Yeah, I don't think that is possible. You could use the "NoRows" property of your table to display a message when no data is returned, but that wouldn't prevent the report from being attached. But at least when they opened the excel file it could print out your custom message instead of an empty document.

Found this somewhere else...
I have a clean solution to this problem, the only down side is that a system administrator must create and maintain the schedule. Try these steps:
Create a subscription for the report with all the required recipients.
Set the subscription to run weekly on yesterday's day (ie if today is Tuesday, select Monday) with the schedule starting on today's date and stopping on today's date. Essentially, this schedule will never run.
Open the newly created job in SQL Management Studio, go to the steps and copy the line of SQL (it will look something like this: EXEC ReportServer.dbo.AddEvent #EventType='TimedSubscription', #EventData='1c2d9808-aa22-4597-6191-f152d7503fff')
Create your own job in SQL with the actual schedule and use something like:
IF EXISTS(SELECT your test criteria...)
BEGIN
EXEC ReportServer.dbo.AddEvent #EventType=... etc.
END

I have had success with using a Data-Driven Subscription and a table containing my subscribers, with the data-driven subscription query looking like this:
SELECT * FROM REPORT_SUBSCRIBERS WHERE EXISTS (SELECT QUERY_FROM_YOUR_REPORT)
In the delivery settings, the recipient is the data column containing my email addresses.
If the inner query returns no rows, then no emails will be sent.
For your purposes, you can take advantage of the "Include Report" and "Comment" delivery settings.
I imagine that a data-driven subscription query like this will work for you:
SELECT 'person1#domain.com; person2#domain.com' AS RECIPIENTS,
CASE WHEN EXISTS (REPORT_QUERY) THEN 'TRUE' ELSE 'FALSE' END AS INCLUDE_REPORT,
CASE WHEN EXISTS (REPORT_QUERY) THEN 'The report is attached' ELSE 'There was no data in this report' END AS COMMENT
Then use those columns in the appropriate fields when configuring the delivery settings for the subscription.

Related

How can I schedule a script in BigQuery?

At last BigQuery supports using ; in the queries, so I can write more than one query in one "block", if I seperate them with semicolon.
If I run the code manually, it works. But I cannot schedule that.
When I want to schedule, I have two choices:
(New) Web UI: I must give a destination table. If I don't do it, I could not save the scheduled query. But all my queries are updates and inserts with different "destination tables". Like these:
UPDATE project.exampledataset.a
SET date = current_date()
WHEN TRUE
;
INSERT INTO project.otherdataset.b
SELECT c,d
FROM project.otherdataset.c
So I cannot even make a scheduling in the Web UI.
Classic UI: I tried this, because the official documentary states, that I should leave the "destination table" blank, and Classic UI allows it. I can setup the scheduling, but it doesn't run, when it should. I get the error message in email "Error status: Dataset specified in the query ('') is not consistent with Destination dataset 'exampledataset'."
AIK scripting (and using semicolon) is a very new feature in BigQuery, but I hope someone can help me.
Yes, I know that I could schedule every query one by one, but I would like to resolve it with one big script.
Looks like the scheduled query was defined earlier with destination dataset defined with APPEND/TRUNCATE type transaction. While updating the same scheduled query to a DML query, GUI doesn't show the dataset field / table name to update to NULL. Hence this error is coming considering the previously set dataset and table name in the scheduled query.
Hence the fix is to delete the scheduled query and create it from scratch with DML query option. It worked for me.
Scripting is supported in scheduled query now. However, scripting query, when being scheduled, doesn't support setting a destination table for now. You still need to use DDL/DML to make change to existing table.
E.g.:
CREATE OR REPLACE TABLE destinationTable AS
SELECT *
FROM sourceTable
WHERE date >= maxDate
As of 2022, the BQ Console UI will let you create a new scheduled query without a destination dataset, but it won't let you update a prior SELECT to use DDL/DML block syntax. However, you can use the BigQuery Data Transfer API to update the destinationDatasetId field, via transferconfigs/patch. Use transferconfigs/list to get the configId for a given scheduled query.
Note that you can either use the in-browser API Explorer, if you have the appropriate credentials, or write a programmatic solution. Also seems useful for setting/updating any other fields, including renaming scheduled queries.

Maximo: Mimic Workflow assignments with an SQL query

I want to write an SQL query that mimics the results in the Maximo Start Center assignments section. The assignments are workflow assignments.
I tried querying the workorder table and specifying the assignedownergroup that the user is in:
select
*
from
workorder
where
status in ('WAPPR','APPR','INPRG')
and assignedownergroup = 'FIRE'
However, the query returns more work orders than what's shown in the Start Center assignments.
How can I write a query to mimic the workflow assignments in the Start Center?
My other answer would work if the portlet you highlighted was a Result Set against WORKORDER, but it is not. The portlet you have highlighted is the Workflow Inbox, which is based on WFASSIGNMENT where assigncode = 'userid'.
A full query that mimics the workflow inbox would look like this, in Oracle SQL:
select
(select 'WO '||wonum||' ('||description||') is waiting for '||wfassignment.description
from workorder
where workorderid = wfassignment.ownerid
and wfassignment.ownertable = 'WORKORDER'
/* Union in other tables */) description,
app
from wfassignment
where assignstatus = 'ACTIVE'
and assigncode = 'JDOE'
I'm not sure where the WO prefix on the assignment description comes from. But since you could add workflow to your own app based on your own object, I would like to think it comes from metadata somewhere instead of code. And the description itself is probably a format string in MAXMESSAGES.
You'll notice the Union in comment in my query, where you would add unioned queries against PR or PM or ASSET or whatever.
The easiest way to get the SQL Maximo is running is:
Go to the Logging application
Select the sql Root Logger and add a "child" Logger of WORKORDER.WORKORDER (that's SERVICE.OBJECT from DB Config) with a Log Level of INFO.
Get ready to open your log file.
Load your start center.
Open your log file.
The SQL issued by Maximo to load the result set should be near the bottom of your log file.

How to schedule a job to run and send out an email only when there are n rows in the table in ssrs

I have a report which is sent daily which has some no. of rows but I want to send a separate report with a subject which says it is "critical" as it has n no. of rows in it.
How do I schedule this in SSRS?
Thank you!
Create a data driven subscription that only returns results if your table contains n rows.
A Data Driven Subscription would be best if you have the Enterprise version of SQL, but if you don't you'll need to get creative. One method that should work is to create a copy of the existing report (if it's TheNinjaReport call the copy TheNinjaReport_Critical or something), and alter the query so that it throws an error if there aren't the requisite number of rows. When the query throws an error, the subscription will fail and nothing will go to the end user. Something like
IF (SELECT COUNT(*) FROM dbo.ErrorLog) > 100
SELECT *
FROM dbo.ErrorLog
ELSE
RAISERROR('Not a critical number of errors', 16, 1)
This is not ideal because now you have two reports to maintain, but it will get you where you need to be.

Pulling data from a SQL table

I have an Intranet, that is SQL based on the back end.
Users submit documents to the Intranet, but sometimes they set an expiry on the document.
There is a table "dbo.article" that lists all these documents, who submitted them and when (if ever) they expire. I get get this data by doing:
SELECT TOP 999 [NEWSID]
,[EXPIRES]
,[HEADLINE]
,[AUTHORID]
,[AUTHOR]
FROM [ARTICLE]
ORDER BY [EXPIRES] ASC
I would like this to run, say once a week, and then email me when an article is about to expire.
What would be the best way to achieve this?
Gavin.
a couple of ways to achieve this,
option 1 - write a stored procedure checking the expiry and sending notification emails if necessary, there are ways to send emails from sql server, for example, this link - How to send email from SQL Server?
option 2 - use some script (vbs or powershell, again, either use stored procedure or plain sql query) and when the condition is met, fire an email, and this is more flexible and could be installed at any client machine (not necessary on the SQL server). one sample on how to send email using vbs - http://social.technet.microsoft.com/Forums/en-US/7779b3bb-dfcc-4ab3-966d-9c71d5369ad7/send-email-using-vbscript
option 3 - implement a simple console app or even win form app to do stuff in option 2, instead of using script.
but all the options require you to add a scheduled task on the installed box to run it at your desired timeframe.

Data Driven Subscriptions SSRS Standard Edition 2008

I'm fairly new to MSSQL and SSRS.
I'm trying to create a data driven subscription in MSSQL 2008 Standard SSRS that does the following.
Email the results of the report to a email address found within the report.
Run Daily
For Example:
Select full_name, email_address from users where (full_name = 'Mark Price')
This would use the email_address column to figure out who to email, This must also work for multiple results with multiple email address's.
The way I'm thinking of doing this is making a subscription to run the query, if no result is found then nothing happens.
But if a result is found then the report changes the row in Subscriptions table to run the report again in the next minute or so with the correct email information found in the results.
Is this a silly idea or not?
I've found a couple blog posts claiming this works but i couldn't understand their code enough to know what it does.
So, Any suggestions on how to go about this or if you can suggest something already out there on the internet with a brief description?
This takes me back to my old job where I wrote a solution to a problem using data-driven subscriptions on our SQL Server 2005 Enterprise development box and then discovered to my dismay that our customer only had Standard.
I bookmarked this post at the time and it looked very promising, but I ended up moving jobs before I had a chance to implement it.
Of course, it is targeted at 2005, but one of the comments seems to suggest it works in 2008 as well.
I've implemented something like this on SQL Server Standard to avoid having to pay for Enterprise. First, I built a report called “Schedule a DDR” (Data Driven Report). That report has these parameters:
Report to schedule: the name of the SSRS report (including folder) that you want to trigger if the data test is met. E.g. "/Accounting/Report1".
Parameter set: a string that will be used to look up the parameters to use in the report. E.g. "ABC".
Query to check if report should be run: a SQL query that will return a single value, either zero or non-zero. Zero will be interpreted as "do not run this report"
Email recipients: a list of semicolon-separated email recipients that will receive the report, if it is run.
Note that the “Schedule a DDR” report is the report we’re actually running here, and it will send its output to me; what it does is run another report – in this case it’s “/Accounting/Report1” and it’s that report that needs these email addresses. So “Schedule a DDR” isn’t really a report, although it’s scheduled and runs like one – it’s a gadget to build and run a report.
I also have a table in SQL defined as follows:
CREATE TABLE [dbo].[ParameterSet](
[ID] [varchar](50) NULL,
[ParameterName] [varchar](50) NULL,
[Value] [varchar](2000) NULL
) ON [PRIMARY]
Each parameter set – "ABC" in this case – has a set of records in the table. In this case the records might be ABC/placecode/AA and ABC/year/2013, meaning that there are two parameters in ABC: placecode and year, and they have values "AA" and "2013".
The dataset for the "Schedule a DDR" report in SSRS is
DDR.dbo.DDR3 #reportName, #parameterSet, #nonZeroQuery, #toEmail;
DDR3 is a stored procedure:
CREATE PROCEDURE [dbo].[DDR3]
#reportName nvarchar(200),
#parameterSet nvarchar(200),
#nonZeroQuery nvarchar(2000),
#toEmail nvarchar(2000)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
select ddr.dbo.RunADDR(#reportName,#parameterSet,#nonZeroQuery,#toEmail) as DDRresult;
END
RunADDR is a CLR. Here's an outline of how it works; I can post some code if anyone wants it.
Set up credentials
Select all the parameters in the ParameterSet table where the parameterSet field matches the parameter set name passed in from the Schedule A DDR report
For each of those parameters
Set up the parameters array to hold the parameters defined in the retrieved rows. (This is how you use the table to fill in parameters dynamically.)
End for
If there’s a “nonZeroQuery” value passed in from Schedule A DDR
Then run the nonZeroQuery and exit if you got zero rows back. (This is how you prevent query execution if some condition is not met; any query that returns something other zero will allow the report to run)
End if
Now ask SSRS to run the report, using the parameters we just extracted from the table, and the report name passed in from Schedule A DDR
Get the output and write it to a local file
Email the file to whatever email addresses were passed in from Schedule A DDR
Instead of creating a subscription to modify the subscriptions table, I would put that piece somewhere else, such as in a SQL agent. But the idea is the same. A regularly running piece of SQL can add or change lines in the subscription table.
A Google of "SSRS Subscription table" returned a few helpful results: Here's an article based on 2005, but the principles should be the same for 2008: This article is for 2008, and is really close to what you are describing as well.
I would just look at the fields one by one in the subscriptions table and determine what you need for each. Try creating a row by hand (a manual insert statement) to send yourself a subscription.
R-Tag supports SSRS data driven reports with SQL Server standard edition
You can use SQL-RD, a third-party solution, to create and run data-driven schedules without having to upgrade to SQL enterprise. It also comes with event-based scheduling (triggers the report on events including database changes, file changes, emails received and so on).