I have a report that returns basic rows of data. I need to filter this and only get data for yesterday. I was looking into adding a filter to the tablix, choosing the date field, setting operator value to =, and then using Today(), but cannot seem to manipulate Today() using -1 or anything similar.
Any other expression suggestion would be welcome.
Also, for the same dataset, I need to filter for yesterday based on one date filed as long as another date field is not the same date. example, amended date is yesterday, but created date is not the same.
There are a couple of ways of achieving this. You can do it via the filter using two filters, first > dateadd("d",-1,Today()) and second < Today(). But I would recommend using parameters in your SQL rather than doing it at the report stage. In your SQLs WHERE clause you can add
WHERE ...
And
[date field] BETWEEN #StartDate and #EndDate
Then you can create two Date/Time type parameters in your report #StartDate and #EndDate and use those to manipulate the data as needed. Then you can set the default for those parameters to be whatever you want and when running the report it will give you (or your end user) a calendar to pick whichever date range you/they like. Again if you wanted only "yesterdays" data you could set your default #StartDate to =dateadd("d",-1,Today()) and your #EndDate default to =Today() That way your extraneous data will be excised at the SQL level meaning you don't waste resources importing more data than you require and you don't have to mess about with changing the filters if you want a one off run of the report for a different date range.
Related
So I have a report with approx 15 datasets.
The report has a date parameter so the user can run for whichever date they want.
Each dataset has sql logic that basically determines:
If #parameter_date does not exist in table
then grab the max date from table < #parameter_date
else
use #parameter date
This works and the report works properly as is.
However, I was trying to see if I can have this sql logic in 1 place (rather than 15 times in the beginning of each dataset query) and store it in a global variable, and pass the proper date into the dataset?
When I look at report properties and "variables" it only looks like I can write an expression, not write sql and return a date based on a query.
I'm sure there is an efficient way of doing this, any help would be appreciated.
Thank you
I'm trying to set two different dates for the same SSRS report.
What the report basically does is check a StartDate and EndDate these dates are default to yesterday.
But I have to implement a new subscription which has to look to the beginning of the month.
I've been investigating and I couldn't see any configuration rather than change the default date, but this will break the first subscription.
I'm thinking to add a boolean flag saying "check from the first" and an if inside the SQL query.
but I would like to know if there is any better approach rather than this "hardcoded" and ugly way, using the subscription if possible.
Thanks.
You can use a data-driven subscription to calculate the parameter values for the new subscription you want to create. Write a SQL query that gets the two date values you want to use. Then you can pass these in to override the defaults. You don't even have to edit the report and it will be dynamic.
I am hoping that someone can help me a SSRS Subscription/Report Query. I have a report that takes 2 date parameters as default startdate = 1st Date of the Current Month, enddate = today's date e.g. startdate = 01/05/2017 enddate = 17/05/2017.
Though these are default dates when the report is run you can also after the initial run change these dates to anything else that you want.
What I want to do is set up a subscription service that runs on 1st of the month and sends the report to a folder on the network.
What I want to do though is replace the startdate and enddate at the point the subscription is run with the startdate and enddate of last month e.g. on the 1st of May the startdate = 01/04/2017 and enddate = 30/04/2017.
What I thought I would do is create a stored procedure in my report with the relevant dates on it for all scenarios that I will need. Set the Last Month one's with default values from the procedure.
Now I can see all date parameters that I might need within the subscription set up but I cant see how I can change the default run time ones when the report is just run on a daily basis by a user to the ones I need it to run for the last month. I know I could just create another report to do this but it seems silly to have multiple reports with only the dates differing and I going forward I am likely to use this logic on other date ranges.
The initial code and idea came from this link "SQL Server: calculating date ranges"
Thanks
Hi R.Richards, since posting the initial query I have been testing a few things with Data Drive Subscription and I think that one of the issues may be due to date format. My report parameters are just set up as date/time but as stated I am wanting to use a function/procedure to call the relevant date splits. The code I am using is in the link that I posted to the original query but I can post it here as well if it helps. When using data driven, if I just use the date default in the report there appears to be no issue but when I select it from the function it errors, the function returns year/month/day timestamp but when I see my defaulted date in the parameter its day/month/year timestamp??
Thanks Phil
I have an (either or) situation in regards to parameters in SSRS 2008. I currently have my report working with a date range but I've been asked to add a drop down for the user to select the weekending date. I've got that drop down working but how can I switch between parameters (Date Range and the use of the Weekending Date drop down) for sending parameters to my report?
The way I allways fix this is by setting the parameters as nullable.
Then in my sql script I select all dates on the weekending date or between the daterange:
So whatever the user specifies, your sql script is filtered based on their parameters.
select *
from [table] t
where t.[date] = #WeekendingDate
or t.[date] is between #DateRangeFrom and #DateRangeTo
I usually handle this situation by creating an Internal Parameter(s) to sit between the UI and the query or stored procedure. The Internal Parameters are driven by expression depending on the user selection.
so lets say you want the user to either select a begin and end date range(Begin: 2012-01-01 End: 2012-01-31), or a month (Jan 2012).
If they select a value for Month. I convert that to an equivalent date range in the internal parameter expression. If they enter a date range I just pass through the begin and end values to the internal parameters.
Hopefully this makes sense. with a little work and imagination I think the approach can handle most scenarios.
One possibility would be to use the version control system of your choice to make another branch for the second report, change that one to use Week Ending, and then just make sure you merge changes every time you make a change to the main report.
I'm sure someone will come up with a cleaner way to handle it, though...
I am writing an SSRS report that has several parameters including a couple of date fields. I do not want the user to be able to enter time information in either date field, but SSRS only has the Date/Time data type. Is there a way to force these report parameters to act as date only, and can I set a specific format (e.g., dd/mm/yyyy)? I would like to keep the built-in date-picker-calendar functionality.
I do not want to write my own report parameter web page because if I did then this one report would be the odd one out given that all of our other reports (which don't use date parameters) work fine with the built-in SSRS parameter entry functionality.
Perhaps the answer is that you can't do it with the built-in options, but that seems crazy - how could something so obvious have been overlooked?
The Google and Stackoverflow searches I've done only gave me ways to set the format in the report output (actually there are a number of cases where people have asked a question similar to mine and only received answers about setting the output format).
The problem is that you are using parameters that get timestamp information.
For example, if you are using Now() in your expressions- you will be asking for the current date AND the current time. However, if you use Today()- you will only be asking for the current date.
=Today() 'returns date only
=Now() 'returns date and current timestamp
Useful references:
http://msdn.microsoft.com/en-us/library/ms157328(v=sql.90).aspx
http://msdn.microsoft.com/en-us/library/ms157328.aspx
To answer my own question based on research I've done since asking it: it seems it is not possible to control how SSRS handles user entry of date/time values in parameters. If there is a need to restrict to date (or time) only or do cross-field validation then you need to implement your own front-end - which unfortunately for my specific business case doesn't help.
In my experience it has only given me the date and time when the filed you are selecting from contains both date and time. I have found if I am selecting on a date only field then I only get the date in the parameter
There is a way, but it will require you to CAST your date as Varchar(10) in your parameter dataset.
Next,You'll have to choose "Data Type:" as Text under Parameters section.
Again, you'll have to make sure your SQL code re-converts it into date again. I do not prefer this way, but users really wanted to see date without time.
Let me know if you'd like screenshot or more detail.