SSRS: Variable that runs query based on a (date) parameter value entered by user? - reporting-services

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

Related

Query Parameter in Paginated Report

I am using Paginated Reports against a dataset in the cloud. I am trying to build a query parameter (not a report parameter). I want the report to function such that when user selects a date in the query parameter dropdown, the results will return the past 13 months, ending on the date they select in the slicer. I only see options for 'equal to', 'begins with','contains', 'range(inclusive)', 'ranage(exclusive)', nd 'custom'. I thought about modifying the query logic that is automatically created, but don't know how to modify it to bring back 13 months of data ending on the date they select in the parameter. Is there a way to do this in the paginated report itself? Trying to avoid having to create a PBI query and pass slicer values. Thanks for any ideas

SSRS Report Builder - Get the date time when the data in the table is updated?

Is it possible to get the datetime when only there are any data changes in the table/matrix?
I don't want to always get the current datetime. I want the datetime to be refreshed only when there is a change to the data in the table/matrix.
This is only possible of you are storing a timestamp in the rows of data that are being queried. If you are storing that timestamp, then simply query it and render it outside of the tablix - you could use a Max() aggregate function to find it from the rows of data.

Filtering Tablix based on date field

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.

Querying based on a data entered in an Access form

I've trying to build a query that will look at various fields that are filled out in an associated form. In particular, I'm looking to query for all records > a certain date. This column in the database is stored as a DateTime. Right now, my query looks as follows: (Note that fromDate is just a textbox.
SELECT * FROM ACM_TABLE where DT_TM>[Forms]![Form1]!fromDate
When I replace this with a hardcoded date in the form mm/dd/yyyy, it returns results, but querying based on what is entered in the form does not. Is there some type of conversion I need to do?
Thanks

Working with parameters in SSRS 2008

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...