Date in Text format- Birt - sql

I need to display a text date like " August, 2018" if it is coming like "08-02-2018".
So, I have written this
" MONTHNAME(MAIL_DATE + 12 DAYS)||', '||YEAR(MAIL_DATE + 12 DAYS) as DateInText " wherein MAIL_DATE is today's date.
And, I have mapped in Birt like row["DateInText "], but I am not getting the value as expected like "August, 2018" .

You can make use of in built BIRT functions to achieve this.
In the detail row of the table, right click on the cell and go to "Edit Value/Expression.."
In the expression you can try this :
BirtDateTime.month(new Date(dataSetRow["DateInText"]),2) + ", " + BirtDateTime.year(new Date(dataSetRow["DateInText"]));
I hope this works.
Thank You

Related

SQL SSRS add if condition into ssrs expression

I am creating a simple report in SSRS
One of the fields is an address, which has this expression value
=First(Fields!BILL_CITY.Value) & ", " & Fields!BILL_PROV.Value & " " & Fields!BILL_ZIP.Value
What I want to do, is within that expression within SSRS, I want to add a condition.
If the Fields!BILL_ZIP.Value is only 5 digits, do nothing.
If the value is more than 5 digits, add a dash after the fifth digit.
So if customer sends the shorthand version of the zipcode it will appear as
45040 but if he sends the long version, it will be 45040-8999
Does anybody know how to do this? Creating the condition probably wouldn't be too hard, but how do I put it within the SSRS expression format?
Try:
= IIF(LENGTH(Fields!BILL_ZIP.Value) = 5, Fields!BILL_ZIP.Value & "-", Fields!BILL_ZIP.Value)

SSRS lookup with datediff Incorrect result error showing in fields

I have to write again this problem. I am not an expert in SSRS.
I have been trying to resolve this issue. Even though the fields are all the same datatype am still getting error and incorrect time difference in the filed in some fields.
I do not know what am doing wrong. This is the code. Please find below screen shot also.
enter code =Datediff(DateInterval.Minute, Fields!health_start_date.Value, Lookup(Fields!flight_date.Value & Fields!register_number.Value & DATEPART(DateInterval.Hour,Fields!health_start_date.Value) , Fields!FL_DATE.Value & Fields!REG.Value & DatePart(DateInterval.Hour, Fields!ATD.Value), Fields!ATD.Value, "DataSetAIMS") ) MOD 60 & " mins "
here
The scenario is that the two fields Health start date and ATD have two different dataset which shows time of flight differently but the time difference is always in minutes. What am trying to do is to compare the two table with their hour and date using lookup to find difference in minutes
Okay, I think I see the problem: you're really close and this stuff trips us all up on occasion. In the LOOKUP function, I think you are joining the two data sets based on:
flight_date = FL_DATE, and
register_number = REG, and
HOUR(health_start_date) = HOUR(ATD)
Which is fine, but the ampersand (&) just "concatenates" strings together, and (a) your strings don't actually match, and (b) HOUR is a number, not a string.
(a) The "date" in the first data set is DDMMYYYY, and in the 2nd it is DDMMYY. I.e., "05222018" is not the same as "052818", so your lookup will not work. It's possible that they are stored correctly as date fields in the database and so the comparison will work fine, but better to force them to match. For that I'd recommend formatting each of the date strings into a standard format, like "FormatDateTime(Fields!flight_date.Value, DateFormat.VBShortDate)".
(b) Should be easy, just add ".ToString" after the parentheses, like "DATEPART(DateInterval.Hour,Fields!health_start_date.Value).ToString()".
(c) I'm assuming the register_number and REG are formatted the same.
Given all that, your new LOOKUP function might look something like this:
=Datediff(DateInterval.Minute,
Fields!health_start_date.Value,
Lookup(
FormatDateTime(Fields!flight_date.Value, DateFormat.VBShortDate) & Fields!register_number.Value & DATEPART(DateInterval.Hour,Fields!health_start_date.Value).ToString() ,
FormatDateTime(Fields!FL_DATE.Value, DateFormat.VBShortDate) & Fields!REG.Value & DatePart(DateInterval.Hour, Fields!ATD.Value).ToString()
, Fields!ATD.Value
, "DataSetAIMS")
).ToString() & " minutes"
However, I think you'd make your life easier by just doing that sort of calculation in the database layer, in the report query, something like:
SELECT
d1.FlightDate
, d1.RegisterNumber
, d1.HealthStartDate
, d2.ATD
, DiffInMinutes = DATEDIFF(MINUTE, d1.HealthStartDate, d2.ATD)
FROM DataSet1 d1
JOIN DataSetAIMS d2
ON CAST(d1.FlightDate AS DATE) = CAST(d2.FL_DATE AS DATE)
AND d1.register_number = d2.REG
AND DATEPART(HOUR, d1.health_start_date) = DATEPART(HOUR, d2.ATD)
This code certainly isn't exact, but hopefully it will get you pointed in the right direction!
Thanks Russel. I have accepted your answer. What I did was to remove the formatdate from the expression code and modify the query design code to convert to the same time date : the code below
=Datediff(DateInterval.Minute, Fields!health_start_date.Value, Lookup(Fields!register_number.Value & DATEPART(DateInterval.Hour,Fields!health_start_date.Value).ToString() , Fields!REG.Value & DatePart(DateInterval.Hour, Fields!ATD.Value).ToString(), Fields!ATD.Value, "DataSetAIMS") ).ToString() MOD 60 & " mins "
or the below as well works :
=Datediff(DateInterval.Minute,
Fields!health_start_date.Value,
Lookup(
Format(Fields!flight_date.Value, "ddMMyy") & Fields!register_number.Value & DATEPART(DateInterval.Hour,Fields!health_start_date.Value).ToString() ,
Format(Fields!FL_DATE.Value, "ddMMyy") & Fields!REG.Value & DatePart(DateInterval.Hour,Fields!ATD.Value).ToString()
, Fields!ATD.Value
, "DataSetAIMS")
).ToString() MOD 60 & " minutes

My Query is not giving the right results in access

SELECT (SignIn.VisitorFirstName & " " & SignIn.VisitorLastName) AS [Visitor Name], SignIn.SignInDateTime AS [Sign In Time], ([UserList.FirstName] & " " & [UserList.LastName]) AS Reason
FROM SignIn INNER JOIN UserList ON SignIn.AssignedPO = UserList.POid
WHERE (((SignIn.Complete)=No) AND ((Format([SignInDateTime],"Short Date")) Between #8/8/2016# And #8/10/2016#))
ORDER BY SignIn.SignInDateTime;
I am getting values for dates outside the scope.
The query runs but returns the wrong values. (see image below)
**
EDIT from comments: It's returning values before August 8th
**
Properties of my DateTime field (SignInDateTime)
Not sure what this conversion/comparison is doing
((Format([SignInDateTime],"Short Date"))
You might be safe to use CDate or just the Field itself - it looks like it's a date time field anyways
If it is a Date/Time field, try changing this
((Format([SignInDateTime],"Short Date"))
To this
([SignInDateTime]

Handling NULL Dates in SSRS

We have a SSRS Report. This report have a field called Actual Date. Whenever this field is null, the report need to show "N/A". To handle this, I have done as below.
="Report End Date: "= IIF(IsNothing(CSTR(First(Fields!Actual_Max_Date.Value, "dataset1"))), "N/A", CSTR(First(Fields!Actual_Max_Date.Value, "dataset1")))
But I always get False as Result. anything wrong in the above expression? Also is it possible to add custom color to the string "N/A"?
Thanks for the help
Use String.IsNullOrEmpty() instead of IsNothing()
and
1st part of your expression (="Report End Date: "=IIF....)
should be ="Report End Date: " + (IIF....))
Example (My report parameter is datetime picker):
="Report End Date: " + (IIF(String.IsNullOrEmpty(Parameters!ReportParameter1.Value),"N/A",Parameters!ReportParameter1.Value))

How do I format the date to include the week number?

I am using Microsoft Business Intelligence Development Studio 2012 trying to create a calculated field that will give me the Month and Week number of a field with the name 'createdon'.
I am new to SQL and after some research this is the code that I have come up with.
=Format(Fields!createdon.Value, "MMMM") & " Week " & (Int(DateDiff("d",DateSerial(Year(Fields!createdon.Value),Month(Fields!createdon.Value),1), Fields!FullDateAlternateKey.Value)/7)+1).ToString
But I am getting the error:
"The Field expression for the dataset 'Dataset1' refers to the field
'FullDateAlternateKey'. Report item expressions can only refer to
fields within the current datasetscop or, if inside an aggregate, the
specified dataset scope. Letters in the names of fields my use the
correct case.
I know this means that "FullDateAlternateKey" is not a valid field name, but I do not know what field name to substitute instead to correct this expression. Does anyone with more experience have any ideas as to how I can correct this?
Ideally, I would like it formatted to have a column that shows "week ending in ".
So any dates from 9/26/2015 to 10/2/2015 would say "Week of 10/2/2015"
Try this:
="Month: " & Datepart("m", Fields!createdon.Value) & " Week: " &
Datepart(DateInterval.WeekOfYear,Fields!createdon.Value)
You will get the following: Month: 10 Week: 43
Edit your question and add a example of the desired result in order to help you with the specific format.
Update:
Try this:
="Today: " & Format(Fields!createdon.Value,"dd/M/yyyy") & "Week Of: " & Format(
DATEADD("d" ,7-DATEPART(DateInterval.WeekDay,Fields!createdon.Value,FirstDayOfWeek.Monday),Fields!createdon.Value),
"dd/M/yyyy")
It will show: Today: 19/10/2015 Week Of: 25/10/2015