I have a report that has two required date parameters which the user enters. I want to create a subscription that runs on Friday that pulls for the previous week's Sunday through Saturday period. So for example, for this coming Friday, the subscription would pull for Jan 29 - Feb 4. I've tried =Now(), =Today(), @ExecutionTime
and then subtracting the number of days but all I get is errors. Is this possible to do?
I did see this link but I wonder if there's a better way. http://www.sqlservercentral.com/articles/Development/datadrivensubscriptions/2432/
SSRS 2008
My favorite trick to handle this situation is to create an Integer parameter called StartWeek. Prompt of "The week starting:" Available values like:
Default value of -1.
Then in your query:
On the report parameter configuration (on development time, not on the subscription creation), add a default value for the parameter. If you do, you will have a check box called "use default value" when creating the subscription
BeginDate
EndDate
So for the upcoming Friday 2/10. This would give you a date range of 1/29 - 2/4.
Yes I have done this, see this post https://stackoverflow.com/a/5539615/168703 You can create a dataset that gets date ranges and use it in your report. Then your subscription can use this date range and change on its own dynamically without manual changes every day/week/month/year/etc.
Reposted here as well, this is your most flexible solution:
I'll also share a set of common date functions I use. Just create this as a table valued function:
Here are the scalar valued functions for these:
These were really helpful for me because I used this in reporting services for date parameters. You could simply create a dataset referencing this table function and then use these in the parameters for any datetime within RS.
You could execute this entire table-valued function like so:
SELECT * FROM [MyDB].[dbo].[udfCommonDates] (GetDate())
The result is like so
For Reporting Services Folks
Now I mentioned earlier that I use these for reporting services. Now the RS folks might be thinking but how does this help me as I need a dataset and a dataset can only be based on a Stored Procedure or a direct table. No problem create the following stored procedure:
Now you've got a stored procedure to use as a dataset...Now in reporting services add a new dataset:
Now go to the report parameters section of the report:
Now pick that dataset dsFunctions (or whatever you called it) and then pick any of the value fields from the scalar functions such as:
Now when you run the report it uses the scalars:
Also now in your "Subscription" you will see a "Use Default" checkbox next to the parameter for the date. If you check this checkbox it will automatically use the default value provided by this custom function. It is very very flexible and a very nice solution in reporting services. Here is a screen print of that: