I want to check current month to many condition as below.
so I take TextField ,edit its pattern to MM & in expression editor edit below code
new java.util.Date()>=4 && new java.util.Date() <= 7 ? "Q1" :
new java.util.Date()>=8 && new java.util.Date() <=11 ? "Q2" : "Q3"
but it gives error
Error filling print... Error evaluating expression : Source text : new java.util.Date()>=4 && new java.util.Date() <= 7 ? "Q1" : new java.util.Date()>=8 && new java.util.Date() <=11 ? "Q2" : "Q3"
Setting up the file resolver..
but when I give expression like
new java.util.Date()== 4 ? "Q1" : "Q2"
It works fine.
Does iReport not able to resolve multiple conditions ? or should I give different TextField with single condition ?
are you sure new java.util.Date() is just give you the month.
try this it will give you the moth
(new SimpleDateFormat("M")).format(new java.util.Date())
also you can use yyyy(year) or d(date) to check
and Integer.parse(...month...) or Date.parse(...month...) maybe needed, if you don't have your Qs as integer or date.
Try using calendar instead.
(Calendar.getInstance()).get(Calendar.MONTH)>=3 && (Calendar.getInstance()).get(Calendar.MONTH)>=6 ? "Q1" :
(Calendar.getInstance()).get(Calendar.MONTH)>=7 && (Calendar.getInstance()).get(Calendar.MONTH)>=10 ? "Q2" : "Q3"
can you please try putting the expression in brackets like
(new java.util.Date()>=4 && new java.util.Date() <= 7 )? "Q1" : (
(new java.util.Date()>=8 && new java.util.Date() <=11 ) ? "Q2" : "Q3")
You can use multiple condition like this
new java.util.Date() >= 4 ?
"Q1" :
new java.util.Date() <= 7 ?
"Q2" :
new java.util.Date() >= 8 ?
"Q3" :
"Q4"
Related
We have upgraded to net 5 / ef core 5, and many of our queries have needed "fixing" due to the changes that have been made.
In reality, the queries were horribly inefficient, because the LINQ could not be translated to SQL and now this has been brought to our attention; one solution is to force this to be worked on the client instead of the SQL Server... however I would like this to make this more efficient.
Below is a query that I can't find a way to do efficiently:
DateTime toDate = DateTime.Now.AddDays(NumberofDays + 1).Date;
MyInsights.AvailableHours = DatabaseContext.WorkCenterSchedules
.Where(x => x.ForWorkCenter.WorkCenterId == WorkCenterID && x.dateTo > DateTime.Now && x.dateTo < toDate)
.Sum(y => (y.dateTo - (DateTime.Now > y.dateFrom ? DateTime.Now : y.dateFrom)).TotalMinutes) / 60;
The error is:
This could be changed to the following:
DateTime toDate = DateTime.Now.AddDays(NumberofDays + 1).Date;
List<WorkCenterSchedule> schedules = DatabaseContext.WorkCenterSchedules
.Where(x => x.ForWorkCenter.WorkCenterId == WorkCenterID && x.dateTo > DateTime.Now && x.dateTo < toDate).ToList();
MyInsights.AvailableHours = schedules.Sum(y => (y.dateTo - (DateTime.Now > y.dateFrom ? DateTime.Now : y.dateFrom)).TotalMinutes) / 60;
However, this is far from ideal. I know EF Core isn't ideal for complex queries, but I feel like I am missing something obvious here, is there something I can do to improve this?
You might be able to leverage SQL Server's DATEDIFF function:
EF.Functions.DateDiffMinute(y.dateTo, DateTime.Now > y.dateFrom ? DateTime.Now : y.dateFrom)
How to use date condition in Symfony (doctrine + oracle) ?
I have trying
$qb = $this->createQueryBuilder('la')
->select('la.id')
->andWhere("la.dateCreated >= TO_DATE(':a', 'yyyy-mm-dd')")
->setParameter('a', '2020-09-01')
->getQuery();
However is error: the query defines 0 parameters and you bound 1
Any Ideas?
In your code, I don't think there should be quotes on ':a', I'd put :
TO_DATE(:a, 'yyyy-mm-dd')
Beside, how about :
$qb = $this->createQueryBuilder('la')
->select('la.id')
->andWhere("la.dateCreated >= :a)
->setParameter('a', '2020-09-01')
->getQuery();
I'm switching from Core Data ( Magical Record ) to Realm and I was wondering if there was an equivalent of MR_findFirst ?
For now, I'm doing :
if ([myRlmObject allObjects].count > 0) {
myRlmObject *myFirstObject = [myRlmObject allObjects][0];
}
Thanks in advance !
You can simplify that and just do:
[myRlmObject allObjects].firstObject
My code is as follows
temp = foreach requiredData generate (recordType == 3 ? controllingCalledNum : callingPtyNum)as ServiceNumber, (recordType == 3 ? callingPtyNum : controllingCalledNum)as DestinationNumber;
Here my code is reduntant..
Can I generate tuple inside '?' operator and do something like this which I can further FLATTERN
temp = foreach requiredData generate (recordType == 3 ? (controllingCalledNum,callingPtyNum) : (callingPtyNum,controllingCalledNum))as (ServiceNumber,DestinationNumber);
I am getting error if I try to do like this
Please help me.
Use the built-in TOTUPLE UDF:
temp = foreach requiredData generate FLATTEN(recordType == 3 ? TOTUPLE(controllingCalledNum,callingPtyNum) : TOTUPLE(callingPtyNum,controllingCalledNum))as (ServiceNumber,DestinationNumber);
I have a bash script , from which i run js file which is responsible to update the table with a new filed if it doesn't exists .
But while executing bash script , i am getting the following error .
Wed Jul 3 00:05:18 Error: error doing update (anon):1552
failed to load: logincount.js
This is a simple js file which will update a field called as yesterday inside userCollection table
var d = new Date();
var curr_date = d.getDate()-1;
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
var yesterday = curr_year + "-" + curr_month + "-" + curr_date;
db.userCollection.update({yesterday : {$exists : false}}, {$set: {yesterday : yesterday}},false,true)
Please let me know if there is any wrong the above js file and what is the reason for this error ??
please advice , thanks in advance
One more thing i have forgot to update if i remove the last line , the below line
db.userCollection.update({yesterday : {$exists : false}}, {$set: {yesterday : yesterday}},false,true)
it doesn't complain anything . i guess that if the filed yesterday should be global or what ?? if yes then how can i make that field global ??
The variable db is not defined. Take a look here: http://docs.mongodb.org/manual/tutorial/write-scripts-for-the-mongo-shell/
You can do this:
conn = new Mongo();
db = conn.getDB("myDatabase");
or this:
db = connect("localhost:27020/myDatabase");