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.
Related
I have searched SO for this question and found slightly similar posts but was unable to adapt to my needs.
I have a database with server requests since forever, each one with a timestamp and i'm trying to come up with a query that allows me to create a heatmatrix chart (CCC HeatGrid).
The sql query result must represent the server load grouped by each hour of each weekday.
Like this: Example table
I just need the SQL query, i know how to create the chart.
Thank you,
Those looks like "counts" of rows.
One of the issues is "sparse" data, we can address that later.
To get the day of the week ('Sunday','Monday',etc.) returned, you can use the DATE_FORMAT function. To get those ordered, we need to include an integer value 0 through 6, or 1 through 7. We can use an ORDER BY clause on that expression to get the rows returned in the order we want.
To get the "hour" across the top, we can use expressions in the SELECT list that conditionally increments the count.
Assuming your timestamp column is named ts, and assuming you want to pull all rows from the year 2014, we start with something like this:
SELECT DAYOFWEEK(t.ts)
, DATE_FORMAT(t.ts,'%W')
FROM mytable t
WHERE t.ts >= '2014-01-01'
AND t.ts < '2015-01-01'
GROUP BY DAYOFWEEK(t.ts)
ORDER BY DAYOFWEEK(t.ts)
(I need to check the MySQL documentation, WEEKDAY and DAYOFWEEK are real similar, but we want the one that returns lowest value for Sunday, and highest value for Saturday... i think we want DAYOFWEEK, easy enough to fix later)
The "trick" now is the columns across the top.
We can extract the "hour" from timestamp using the DATE_FORMAT() function, the HOUR() function, or an EXTRACT() function... take your pick.
The expressions we want are going to return a 1 if the timestamp is in the specified hour, and a zero otherwise. Then, we can use a SUM() aggregate to count up the 1. A boolean expression returns a value of 1 for TRUE and 0 for FALSE.
, SUM( HOUR(t.ts)=0 ) AS `h0`
, SUM( HOUR(t.ts)=1 ) AS `h1`
, SUM( HOUR(t.ts)=2 ) AS `h2`
, '...'
, SUM( HOUR(t.ts)=22 ) AS `h22`
, SUM( HOUR(t.ts)=23 ) AS `h23`
A boolean expression can also evaluate to NULL, but since we have a predicate (i.e. condition in the WHERE clause) that ensures us that ts can't be NULL, that won't be an issue.
The other issue we can encounter (as I mentioned earlier) is "sparse" data. To illustrate that, consider what happens (with our query) if there are no rows that have a ts value for a Monday. What happens is that we don't get a row in the resultset for Monday. If it does happen that a row is "missing" for Monday (or any day of the week), we do know that all of the hourly counts across the "missing" Monday row would all be zero.
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.
im using a query to get data between dates but for some reason it does not pull the data of the last date selected here is my query:
SELECT * FROM order WHERE status = "completed" AND orderdate >= ? AND orderdate <= ? ORDER BY orderid DESC
Im using is equal to or less then... but still?
what am i doing wrong ?
SELECT * FROM order WHERE status = "completed" AND date(orderdate) >= date(?) AND date(orderdate) <= date(?) ORDER BY orderid DESC
It happened with me also, but in my case instead of passing a date I was querying using a datetime variable, Please make sure you are querying with date variable only.
Make sure that orderdate is date as well as your query parameter is also date, or use appropriate function to convert them in date, than query.
Your dates are actually datetimes - so you are actually, in the case of the upperbound, saying "12 midnight" on whichever date you choose. Hence, if it tries to test a value at say 10am in the morning, it fails as being outside the range.
Either set the upperbound date one day forward, or explicitly only test the date part of the datetime...
I am passing a date parameter and in SSRS Dataset Filters I am filtering the tasks whose created date is below the parameter passed date
=cdate(Fields!WI_CreatedDate.Value)
>=
= (Parameters!SinceDate.Value)
If I want to check the condition for task Closed date & tasked resolved date, then How can I mention it in the parameter or there is any other way around ?
Condition should be like
Sincedate <= (CreatedDate or Closed date or Resolved date)
You should be able to handle this by using an IIf expression to perform the check and return a pass/fail condition, something like:
=IIf(Parameters!Sincedate.Value <= Fields!CreatedDate.Value
or Parameters!Sincedate.Value <= Fields!ClosedDate.Value
or Parameters!Sincedate.Value <= Fields!ResolvedDate.Value
, true
, false)
Set this as a boolean filter to show when the expression = true.
This way it will display rows that fulfil at least one of the checked.
I am a newbie to crystal reports, I have a crystal report for which I have a data source from which I am using some fields on to the report.
Crsytal Report Name : InventoryReport
Data Source : I am giving Stored Procedure -- GetInventoryData
Fields : ItemID, ShippedDate, ItemName
I have to get all items which are shipped in between FromData and ToDate of ShippedDate, so I am using formula {GetInventoryData;1.ShippedDate} in {?FromDate} to {?ToDate}
dataType of Shipped Date is String and I have to convert to Date as it needs to be compared but I am having issues in that...
ShippedDate value will be : 2011-04-19 16:02:14.0000000
I have to convert at crystal reports side only..
Please help me how can I cast it to date
actually even better don't use that formula .... in selection formula using the date range explained above
date(split({GetInventoryData;1.ShippedDate}," ")[1]) in {?daterange}
If you are using string, you may do a simple less-than or greater than like:
...where ShippedDate >= '2011-04-19 00:00:00' and ShippedDate <= '2011-04-19 23:59:59'
this is like:
...where ShippedDate >= '<from-date> 00:00:00' and ShippedDate <= '<to-date> 23:59:59'
This would work and you'll not have to cast to a date.
You may also use as (If it works for you):
...where ShippedDate >= '<from-date>' and ShippedDate <= '<to-date>'
one way ... create a formula called cvtDate
date(
tonumber(split({GetInventoryData;1.ShippedDate},"-")[1])
,
tonumber(split({GetInventoryData;1.ShippedDate},"-")[2])
,
tonumber(split({GetInventoryData;1.ShippedDate},"-")[3])
)
then instead of creating two date parameters.. create only one called daterange that allows range values under values options
Then selection formula would be
{#cvtDate} in {?daterange}