At SSRS, one of my reports have date range as parameter - From Date (#FD) and To Date (#TD), these two parameters pass at query for the report to generate
At SSRS the parameter is of date/time type, I'm looking for a solution whereby when user select a date range it should include the time factor as below
if the user has selected say, FD 01/09/2018 and TD 30/09/2018 from report date picker
then I want the parameter to pass as 2018-09-01 00:00:00.000 and 2018-09-30 23:59:59.000 to the query. This 00:00:00.000 and 23:59:59.000 as a fixed range suffix to date.
How to achieve it?
I was trying combinations, this one i found working sort of.. got some clues for many forum
declare #FFD datetime2
declare #TTD datetime2
set #FFD = cast ('2018-09-01' as DATE)
set #TTD = DATEADD(s, -1, DATEADD(S, 86400, '2018-09-30'))
print #FFD
print #TTD
Related
I see a mystery behaviour in my *.rdl. I have 2 datasets defined.
I have 4 parameters defined,
StartDate,EndDate, companyid, sitecode
For both datasets,I have defined a select query.
DatasetA uses #Enddate
DatasetB not using it( it uses, startdate, companyid, sitecode)
I want to getrid of #EndDate from datasetA too. So, im using #startdate parameter to define enddate and using that in my sql query.
eg :
DECLARE #eDate AS date =EOMonth(#StartDate)
But after getting rid of this, #EndDate, my second data retrieves less data.(ie: if it should return data from september and october, now it returns only from September)
I checked the rdl, rowgroup/column group everywhere, but there is no any filter defined like that. I see this behaviour, only if i change #EndDate parameter from 1st dataset.
eg:
DECLARE #eDate AS date =EOMonth(#StartDate)
Select ..
Where date>=#StartDate AND date<=#Enddate to date<=#eDate
Is there any place we use parameter as a filter check? If so, how can I check it, where it has been used in the *.rdl?
I figured out the issue. This is due to Lookup function I use between both datasets. So, when dataset2 is trying to retrieve the correct number of rows, dataset1 was controlling it, becuase it didnt return rows for that date.
eg: dataset1 returns September data, while dataset 2 returns September+October data.
Due to lookup function, Dataset1 controls the dataset2's October data.
I have a report of customers that I wish to run in SSRS. The report I want to return is for a particular period (e.g. 01/01/2016 and 29/02/2016). The parameter is against a date field (End_Date).
What I would like to return is a list of customers WHERE End_Date is either BETWEEN the dates above (or any other period) and WHERE End_Date IS NULL too.
I am able to create a parameter that will list customers with an End_Date between the dates I want but how do I also get the parameter to also list the NULL values.
Hopefully that's clear but just in case - I need a list of customers where End_Date is between two dates or NULL.
Thank you
You need to account for the possibility of a null in your evaluation using an OR for the END_DATE.
Are you using the parameter in the query or on the dataset? The SQL is a bit different that the SSRS expression.
SQL
WHERE DATE_FIELD >= #START_DATE AND (DATE_FIELD <= #END_DATE OR #END_DATE IS NULL)
SSRS
=IIF(Fields!DATE_FIELD.Value >= Parameters!START_DATE.Value AND (Fields!DATE_FIELD.Value <= Parameters!END_DATE.Value OR ISNOTHING(Parameters!END_DATE.Value), 1, 0)
In the other filter properties, set the type to Integer, Operator to =, and Value to 1.
This will evaluate the expression and return 1 if it matches and 0 if not - then it filters for the 1.
I'm trying to sum a net balance based on the earliest date in an SSRS report. In this case there are only 2 dates, but there can be more dates not more than 7 days.
Here's a sample of my data:
Here's what I'm trying to get with the earliest date of 10/26/15:
I've tried the following code, but not able to get this to work:
=Sum(IIf(DateDiff("d",Fields!SettleFullDate.Value,today())>=7
and DateDiff("d", Fields!SettleFullDate.Value, today())<7
and Fields!SETTLEBALANCE.Value>0), Fields!SETTLEBALANCE.Value, 0)
Update: I tried the code below and keep getting an error on the report. Could it be that I need to change the date field to an integer?
Thanks in advance for your help!
To compare the sum of values of two dates, the maximum and minimum in a set you can use the following equation
=Sum(iif(Fields!myDate.Value = Max(Fields!myDate.Value), Fields!myVal.Value, 0))
-Sum(iif(Fields!myDate.Value = MIN(Fields!myDate.Value), Fields!myVal.Value, 0))
This Sums all the values that match the maximum date in the dataset together, and sums all the values that match the minimum date in the dataset together, and takes one from the other.
It is irrespective of which dates you ask to be received, the above approach will work only against the records that you return to SSRS. So if you have a filter (WHERE clause) to return records between Date1 and Date2 this will still apply (Note - don't actually use 'Between' in the query)
Rather than using the maximum and minimum dates as listed here, you could also calculate a date similar to your original approach using
dateadd("d", -7, Fields!MySpecificDate.Value)
And insert that to the expression above.
Hopefully this is what you require - if not please let me know.
How do I build an expression in SSRS that only captures the Month and Year and not the day from a datestamp field?
I am trying to create a Month To Date column in SSRS. I have a date timestamp field, I also created a Month field and a Year field in hopes of solving my own problem. I didn't.
I have an expression built that allows me to capture the month and it works, but in my data set I have July data for both 2013 and 2014. This expression I only want to capture 2014.
=Count(IIF(Fields!Date_Month.Value = Month(Today()), Fields!AcctNo.Value, Nothing),
"Eligibility")
and I got it to work for the Year:
=Count(IIF(Fields!Year.Value = Year(Today()), Fields!AcctNo.Value, Nothing),
"Eligibility")
Can I somehow combine the 2 expressions? Should I?
Orrrrrrrrrr
I have tried to use my datestamp field to no avial: I get #Error with this abomination
=Count(IIF(Fields!Datestamp.Value = Month(Today()), Fields!AcctNo.Value,
Nothing), "Eligibility")
I'd think the preferred way is to use my above datestamp field and parse out the month and year. It's the way I'd do it....if I knew how to actually do it.
As you've suggested, you can combine the two expressions you have to get your required result with a few small changes:
=Count(IIf(Year(Fields!Datestamp.Value) = Year(Today)
and Month(Fields!Datestamp.Value) = Month(Today)
, Fields!AcctNo.Value
, Nothing)
, "Eligibility")
This will count all rows in the Dataset that have the same year and month as the current date.
I am working on a data query and one of my fields has a time format of '33600' and is a data type (INT). I need to know how to convert the field so that it displays the correct time format of HH:MM:SS. The current query I used gives me the date/time as MM/DD/YYYY:00:00:00.
Ex: Convert(datetime,Cast(Ap.aptApptTime as varchar(6),3)as Appt_time
This produces the correct appointment date but gives 00:00:00 for the time. I need to display just the correct time based on a value like '33600'.
Any help on this would be greatly appreciated.
If 33600 is a count of milliseconds, this should work.
DECLARE #Var TIME = '00:00'
SELECT DATEADD(MS, 33600, #Var)
If seconds;
DECLARE #Var TIME = '00:00'
SELECT DATEADD(S, 33600, #Var)
Etc...
Assuming that 33600 is the number of seconds, you could also try
Cast(Cast((33600/86400.0) as smalldatetime) as time)
Where 86400.0 is the total number of seconds in a day. Don't forget the ".0" or SQL will treat it as an integer and the result will always be zero or midnight. You also can't cast directly from a number to a time field, so you have to use an intermediate smalldatetime field.