Data Driven Subscriptions On A Budget

Data Driven subscriptions in SQL Server Reporting Services (SSRS) is only available if you have the Enterprise or BI Editions for 2012 & 2014, Enterprise or Data Center Editions for 2008R2 or Enterprise for 2008. But what happens when the money is not in the budget for those versions? Can you still get Data Driven subscriptions? The answer is You Bet!

I have worked in large shops in the past where purchasing the Enterprise Edition of SQL Server was never an issue, in fact, it was the standard flavor of SQL Server. But when I switched to a smaller shop, where cost was an issue, I had to say good-bye to all those lovely Enterprise features that I have come to know and love. As the proverb goes, “Necessity is the mother of invention”. So when I was asked to essentially create a data driven subscription in Reporting Services, I paused ever so slightly, then said, “Yeah, I can do that”.

There are a few things you can do with a data driven subscription in SSRS

  1. Trigger the execution of a report based on data
  2. Provide parameters to filter the report data at run time
  3. Distribute a report to a fluctuating list of subscribers
  4. Vary the output format and delivery options.

In this post I will address point 1 only, hopefully at some point I will get around to creating a post about points 2, 3 & 4, but for now, it’s just 1.

Trigger the Execution of a report

Let’s say I have a sales report that needs to go out on a daily basis. This report contains sales for the previous day. But what happens when there are no sales? Our report shows up with no data on it. Now we, as data people, completely understand why this happens, but those in the C-Suite don’t always understand and they think the report is “broken”. This initiates a call to the help desk saying simply, “The Daily Sales Report is broken”. We freak out, thinking, “Great, who promoted what?” We instantly go into trouble shooting mode. But after running the report, seeing no data and running the underlying query, we now understand. The report is not “broken”, there were just no sales. I don’t know about anybody else, but I don’t like those in the C-Suite thinking that we in the dungeon are idiots. So instead of sending them a report with no data, we need to send them an email to let them know there were no sales the previous day. Problem solved, crisis averted, get back to work. Oh but wait, I don’t have the appropriate edition of SQL Server, how the heck can I do this? In three easy steps, that’s how:

  1. Create a subscription to your Daily Sales Report in Report Manager, schedule it for a one time execution at a time just a few minutes in the future, and remember the execution time. (This creates the SQL Agent job in SQL Server.)
  2. Take a look at your SQL Agent jobs in SQL Server. If you have never seen or noticed a job created by SSRS, then you will be wondering where your job is because SSRS does not use human readable names for its jobs, it uses those pesky GUIDs as names, ugh! If your server has lots of jobs you may need to sort your jobs by Category to get all the “Report Server” jobs together. Find the job that executed at the time you scheduled (this is why you needed to remember the time!), this will be the job you will need to reference later.
  3. Create a new SQL Agent job and add a step for executing Transact SQL script. In this newly created step write a query that checks for sales from the previous day, if sales exist, then execute the job that was created by SSRS, otherwise send an email stating that there were no sales. There are several ways you can do either one of these things, but here’s my T-SQL script:

DECLARE @SalesTotal numeric(18,2)
, @Yesterday date
, @BodyMessage nvarchar(max)

SET @Yesterday = DATEADD(DAY, -1, GETDATE())

SELECT @BodyMessage = N'There were no sales for ' + CAST(@Yesterday AS varchar(10))

SELECT @SalesTotal = SUM(InvoicedAmount)
FROM dbo.Sales
WHERE SaleDate = @Yesterday

IF @SalesTotal > 0
BEGIN
EXEC msdb.dbo.sp_start_job @job_name = '4D3D4A1F-F007-4045-B5F6-3C86445D153B'
END
ELSE
BEGIN
EXEC msdb.dbo.sp_send_dbmail @recipients = 'recipient@servername.com',
@subject = 'Daily Sales Report',
@body = @BodyMessage
END

Now schedule this newly created SQL Agent job for the time you need your Daily Sales Report to be executed and Wa-La, you now have a data driven subscription for your SSRS report.

There is one really big assumption here, since it’s a small shop, the SSRS instance and the instance where your data live are one in the same. This is easily adaptable if they are not on the same instance by creating a linked server, yes I feel dirty even suggesting it, but like I said, “Necessity is the mother of invention”.

Disheartening Apples

Question:  How many Oracle DBAs can you fit in Madison Square Garden?

Answer:  None, their egos won’t fit through the door.

No, this blog is not a slight towards Oracle DBAs.  I have several friends who are Oracle DBAs and they are some of the nicest, most humble people you will ever meet, but in my experience, they are the exception.  Early in my career I had to administer Oracle and the person I was supposed to learn from was a hard core Oracle DBA and had been for years.  Probably one of the smartest people I’ve ever worked with but only barely tolerable to be around because his ego was larger than the Goodyear Blimp.  When I was introduced to SQL Server way back in 1996 (yes, I am dating myself), there really weren’t any experts in the field readily available when questions came up.  The internet was just starting to flourish and Google hadn’t even been invented yet.  There were a few guys that I had heard of that were willing to help, Brian Knight, Andy Warren & Steve Jones.  I knew about them because Steve Jones was a local guy in Denver, where I was living at the time.  They created this thing called SQLServerCentral.com.  These few are the epitome of SQL Server stewards, for both knowledge and professionalism.  Smart, humble, easy going, willing to share knowledge freely and did I mention smart?  Honestly, they have been my role models for “lifting as you climb” in my career.  Okay, now I sound like some creepy stalker, so we’ll move on to the point of this blog.

For those that know me personally, you know I am not a speaker type, so I give back to the SQL community by volunteering behind the scenes in any way I can.  So when I was selected to work on the program committee for PASS Summit 2014, I was so excited I did a little happy dance in my cube at work.  My co-workers are used to seeing my head bob to the music of my headphones, but seeing me do a happy dance was a little startling for some.  This will be my 5th year on the committee, more specifically the abstraction review team.  I love being on the abstract review team, getting to read what people are passionate about teaching is always so exciting.  It kick starts my love of SQL Server and learning.  However, just because I had been on the committee in previous years, I never assumed I would be selected again.  It is such a privilege to be chosen, and trusted, with this huge task.

Recently there has been a lot of chatter in social media about the selection process (or lack thereof according to some).  It saddens me to see some people’s true colors.  Being chosen to speak for any engagement, not just the PASS Summit, is a privilege, not a <insert deity here> given right.  The selection process has improved over the years and has become more streamlined thanks to the investment made by the PASS IT team.  It still has room for improvement, but most things do.  One of the things I like best about this year is the increase in the amount of time we have been given to review the abstracts.  In years past, we’ve had a very small window in which to review the abstracts.  That small window made it very difficult to coordinate team members’ schedules to discuss final rankings and assign rejection reasons.  I am hoping we can do a much better job this year of providing useful feedback to speakers.  Another improvement that was implemented last year was the removal of the speaker from the abstract.  This is a huge deal.  In years past, we could see who submitted the session and I fear that it swayed team members’ opinions of abstracts, both good and bad.  Some would be chosen because they were “well known” speakers and/or authors, it didn’t matter that their abstracts were poorly written, which in my experience often translated into poorly presented sessions.  Some would be excluded for the exact same reason.   As a speaker you need to have enough respect for your audience to provide them with the best written abstract you can, it’s the surest sign of respect.

I congratulate all those that have submitted sessions for the Summit; it’s a huge step just submitting a session for the PASS Summit.  If you are selected to speak, I ask that you remember that it’s a privilege and an honor and that you treat those attending your session(s) with the respect they are due.  If you are not selected, I ask that you not give up.  If you have questions about why your session was not selected, ask.  I have been asked in the past and am always glad to provide additional feedback.

Question:  How many SQL Server DBAs can you fit in the Seattle Convention Center?

Answer:  Unlimited, as long as they remember why they attend and/or speak at the PASS Summit.

Will You Vote?

Voting is one of the many privileges that I have as an American citizen.  It’s a privilege that most Americans take for granted today.  My dad always used to say, “If you don’t like something, change it.”  That’s exactly what voting allows us to do.

What does voting have to do with SQL Server?  Starting on September 25th, everything.  The Professional Association of SQL Server (PASS) Board of Directors elections start that day.  There’s a great slate this year.  Congratulations to all who made it through the Nomination Committee (NomCom) and my sincere thanks to those volunteers on the NomCom for all your hard work to get us to this point.  The rest of the work is up to you, the PASS community.  Will you do your hard work to make sure we have a great Board of Directors?  Will you read about each candidate and their platform?  Will you take the time to vote?

Voting is a very personal thing and I don’t normally share this kind of thing with other people, but after personally witnessing the energy and PASSion that Allen Kinsel puts into our community, I feel I need to state publicly that he has my vote.  I have worked with Allen in the past so it is a very easy decision.  That doesn’t mean my work stops there.  There are still two more seats available and I need to do the work to make sure that I select the right candidates who will represent what is important to me.

Voting itself is easy, takes less than 5 minutes of your time, but will you do the hard work to make sure the issues that are of concern to you, as a community member, are being addressed?  I urge you to read about the candidates and their qualifications and then VOTE!  It’s your community.

Saving Grace

According to Merriam-Webster the definition of grace is:

1a : unmerited divine assistance given humans for their regeneration or sanctification; b : a virtue coming from God; c : a state of sanctification enjoyed through divine grace; 2a : approval, favor <stayed in his good graces>; b archaic : mercy, pardon; c : a special favor : privilege <each in his place, by right, not grace, shall rule his heritage — Rudyard Kipling>; d : disposition to or an act or instance of kindness, courtesy, or clemency; e : a temporary exemption : reprieve; 3a : a charming or attractive trait or characteristic…

That’s quite a lengthy definition; in fact, I captured less than half of what was in the dictionary.  It seems like a lot of words to describe something so simple.

So what does grace have to do with a blog about SQL Server?  Quite a lot actually.

When I first went to college, I wanted to be a teacher; in fact, I wanted to be a math teacher.  I had this great math teacher who inspired me in high school.  He was not only brilliant, but he was infectious with his desire for learning.  He was a young guy, I think it was his first teaching job, but you could tell that teaching was what he was meant to do.  He would explain things in a way that made sense (that’s a gift when teaching high school sophomores abstract algebra).  If he could see that the class was completely lost, he would change mid stride and go a completely different direction.  I don’t think a single person failed that class, he wouldn’t let them.  He was the definition of grace, “..disposition to or an act or instance of kindness, courtesy, or clemency…a charming or attractive trait or characteristic”.

There was another math teacher in my high school.  He was old (probably forty or something crazy like that) and a bit pompous; he had the letters “PhD” behind his name.  His attitude was that he had the credentials, so if you didn’t understand what he was talking about, maybe you didn’t belong in abstract algebra.  He also had a reserved parking space close the entrance, because he had those three little letters after his name, “PhD”.  He was the exact opposite of grace and almost half his class failed.

The point I’m trying to make is that for some people, their driving force is ego, not love of learning and therefore they have no grace.

I recently attended the SQL Saturday event in Atlanta.  I love these events because they are so personal.  You have smaller classes and you can actually interact with the presenters and most of them are just like you and me, regular people.  However, in Atlanta I noticed a very disheartening trend.  Ego is taking hold and grace is losing ground.

I am not a speaker and I never will be.  I have a horrible phobia of public speaking (which is the reason I didn’t become a teacher).  But I want to give back to the community that has helped me get where I am today, so I volunteer behind the scenes for many things.  Atlanta was no different.  I was attending, but I was also a volunteer.  There were some great nationally and internationally known speakers presenting, in addition to the local and regional people and it was so exciting to be part of the largest SQL Saturday event to date.  As it turns out, it was probably the most disappointing PASS event I’d attended to date.  Not because I was disappointed in the content of the sessions I attended or even in the speakers that presented them, but because there were many other speakers who seem to have lost their grace.

I’m not going to give specific examples or name names (that just elicits finger pointing).  But what I am going to do is ask you, as a speaker, why do you do it?  Is it because you have those three little letters, “MVP”, after your name or is because you want to share your knowledge and inspire others to learn more?  If it’s the latter, I applaud you and ask that you keep on doing what you are doing.  We in the community appreciate all your hard work and your generosity in sharing.  If it’s the former then I might suggest you try to save grace and have a slice of humble pie, it never hurt anyone.

Angela Henry

@SQLSwimmer