I have a query similar to this one, when i execute in the sql/developer it works perfectly, it checks the sysdate correctly:
SELECT *
FROM TB_ADT_AEAT_ESTADOS
WHERE F_MODIF < SYSDATE-5/1440;
But when i launch my code and the same query is executed in myBatis, the query works but doesn´t check correctly the sysdate-x/1440 operation, i pass the X parameter like an Integer in the mapper:
<select id="xxx" resultMap="xxx">
SELECT *
FROM TB_ADT_AEAT_ESTADOS
WHERE F_MODIF < SYSDATE-#{paramIpass}/1440
</select>
Thank you
Sorry, already figured it out. The query is more complex with multiply join and union and in the Constants i passed duplicate values and the result i needed to check date was checked but the next union query still was giving me he results without checking date.
Sorry is someone lost his time trying to see something similar, thank you again, my mistake.
Related
I want to select today's visited urls from the firefox database places.sqlite.
As first attempt, the query I used to accomplish this was (see the operator >):
SELECT datetime(moz_places.last_visit_date/1000000,'unixepoch'), moz_places.title
FROM moz_places
WHERE moz_places.last_visit_date/1000000>strftime('%s','now','start of day')
ORDER BY moz_places.last_visit_date DESC;
The answer to this query is nothing.
Then I changed the query to this, which is pretty much the same (see the operators - and >):
SELECT datetime(moz_places.last_visit_date/1000000,'unixepoch'), moz_places.title
FROM moz_places
WHERE moz_places.last_visit_date/1000000-strftime('%s','now','start of day')>0
ORDER BY moz_places.last_visit_date DESC;
then the answer is correct.
Does anybody out there know why > works in one query by does not in the other?
The strftime() function always returns a string, and a string always compares larger than a number.
When you try to use a string with addition/subtraction, it is automatically converted into a number first, so the result of last_visit_date-strftime(...) is a number.
You could change the function call in the original query to:
CAST(strftime('%s', ...) AS NUMBER)
or, less obvious, if you want to save typing:
strftime('%s', ...)+0
My following query is working..
SELECT d.pub_user.userid FROM d where d.pri_data.user.email="xxx#yyy.zzz"
This gives me result as below..
[
{
"userid": "1e4491ef27097262"
},.....
]
The following query is also working..
SELECT * FROM c WHERE c.pub_user.userid IN ("1e4491ef27097262")
But, when I try the following, it does not work..
SELECT * FROM c WHERE c.pub_user.userid IN (SELECT d.pub_user.userid FROM d where d.pri_data.user.email="xxx#yyy.zzz")
It gives an error.. Syntax error, incorrect syntax near 'SELECT'
Any help is sincerely appreciated.
Thanks
subquery is currently not supported. As per this answer, you can try to leverage a stored procedure.
When one start hitting joins or subquery is an early indicator that your data document structure is not optimal. I am however wondering why you cannot query by email without subquery in your final example. Like this
SELECT * FROM c WHERE c.pri_data.user.email="xxx#yyy.zzz"
If this is not possible because these data are in separate documents perhaps email could be added to the docments.
I'm experiencing a really odd result when I do a count in X++, something I've not experienced before. I am performing what I thought was a really simply count query, but I can't seem to get the result I am after.
WMSOrderTrans orderTrans;
WMSOrderTrans orderTransChk;
;
select count(RecId) from orderTrans group by shipmentid where orderTrans.inventTransRefId == 'XXXXXX';
info(strFmt('Count is %1', orderTrans.RecId));
while select orderTransChk group by shipmentid where orderTransChk.inventTransRefId == 'XXXXXX' {
info(strFmt('Shipment is %1', orderTransChk.shipmentId));
}
The data set that I am selecting all have only 1 shipmentid, so the first select I am expecting a count of 1, instead I get 4 (which is how many lines for that transrefid exist). If I change the count from 'RecId' to 'ShipmentId', then instead of the count, I get actual shipmentId. I simply want it to return the count of the records, which is what I believe I've asked it to do.
I really can't see what I am missing.
In the while select, I get what I expect (the shipmentid), only 1 infolog message for the loop. This tells me that the group by with the where clause is working, but it doesn't explain why the first count select statement isn't behaving as I would expect.
For reference, this is AX2012 R1 system.
For anyone who might be interested in knowing my answer, it's tied up with Jeff's response. At the end of the day, I didn't look at data well enough, and the query returned the correct results. I initially thought there were a number of unique shipments, but I was wrong. My expected result was erroneous. There were 4 lines in the file, but the lines were unique for the item, not the shipment. They were all on the same shipment. So really, my own fault, it goes to show that one really needs to look at the data closely.
Thanks to all that responded, greatly appreciated.
I would try a database sync, then restarting the AOS. I don't see anything obviously wrong, so it points to bouncing everything.
Try getting the select statement via this method (from memory so check syntax) and then review the query against SQL directly. It uses generateOnly.
select generateOnly count(RecId) from orderTrans group by shipmentid where orderTrans.inventTransRefId == 'XXXXXX';
info(orderTrans.getSQLStatement());
If I understand what you try to achieve, you'd like to get something like this SQL query:
select count(distinct shipmentid) from orderTrans
where inventTransRefId = 'XXXXXX'
The 'distinct' keyword is not available in AX select command. The group by clause will allow you to iterate all distinct values but not to use an aggregate on top of it.
You may use a sql connection to push the exact sql command you want.
In AX, aggregate values are stores in the field used: Count(RecId), the count will go in the recid field otherwise the system may need to add new field on the buffer on the fly. I don't think you can aggregate on the group by clause as it's important to have its value.
You can try (I don't have an AX to test it) to use a query:
Query query = new Query();
QueryRun queryRun;
QueryBuildDataSource qbd;
qbd = query.addDataSource(tablenum(OrderTrans));
qbd.addRange(fieldNum(OrderTrans, InventTransId)).value("xxxx");
qbd.addSortField(fieldNum(OrderTrans, ShipmentId));
qbd.SortOrder(SortOrder::GroupBy);
queryRun = new QueryRun(query);
info(strfmt("Total Records in Query %1",SysQuery::countTotal(queryRun)));
Please help with the error ORA-01427. I am using spring3-JPA2 and the following query throws out ORA-01427.
I need to understand which part of the query is treated as a subquery. Or is it the view code which is throwing it? Please note it happens only for a couple of records we test with.
SELECT *
FROM VW_GET_GROUP_QUEUE taskgroup
WHERE taskgroup.COMPONENT_ID=?1
AND taskgroup.ROLE_CODE=?2
AND ((taskgroup.WORK_ITEM_TYPE LIKE ?3
OR taskgroup.WORK_ITEM_TYPE IS NULL))
AND taskgroup.SOEID=?4
AND ROWNUM=1
I have a question on creating running totals in MS Access 2010 similar to the one here:
Access 2010 - query showing running total for multiple records, dropping old record and adding new record on each line
However when I input the equivalent code from that thread I get an error saying that the database cannot be found (Access seems to think the table I have specified is the database name)
Here is the code from the original thread:-
SELECT hbep1.EmployeeID, hbep1.PayPeriodID,
(
SELECT Sum(hbep2.HoursUsed)
FROM Hours_by_Empl_PP hbep2
WHERE hbep2.EmployeeID=hbep1.EmployeeID
AND (hbep2.PayPeriodID Between hbep1.[PayPeriodID]-3
And hbep1.[PayPeriodID])
) AS Sum_of_Hours_last_4_PPs
FROM Hours_by_Empl_PP hbep1;
Here is the code I inputted into my query:-
SELECT
V4_Try.ID_NIS_INV_HDR,
V4_Try.ID_ITM,
V4_Try.RunTot3,
V4_Try.BomVsActQty,
DMin("RunTot3","V4_Try","[ID_Itm]=" & [ID_ITM]) AS IDItmMin,
DMax("RunTot3","V4_Try","[ID_Itm]=" & [ID_ITM]) AS IDItmMax,
(
SELECT Sum([V4_Try].[BomVsActQty])
FROM [V4_Try].[BomVsActQty]
WHERE [V4_Try].[ID_ITM]=[V4_Try].[ID_ITM]
AND (IDItmMax < IDItmMin)
) AS RunTot6
FROM V4_Try
ORDER BY V4_Try.ID_ITM, V4_Try.RunTot3;
One thing I notice is that the main query uses DMax() and DMin() to create some aliased columns
...
DMin("RunTot3","V4_Try","[ID_Itm]=" & [ID_ITM]) AS IDItmMin,
DMax("RunTot3","V4_Try","[ID_Itm]=" & [ID_ITM]) AS IDItmMax,
...
and then the subquery tries to use those aliases in its WHERE clause
(
SELECT ...
WHERE...
AND (IDItmMax < IDItmMin)
) AS RunTot6
I'm pretty sure that the subquery will have no knowledge of the column aliases in the "parent" query, so they may be the items that are unrecognized.
Start by running this query:
SELECT * FROM V4_Try;
Then develop for complexity. Build the nested query before anything else. When you know that runs, try adding your aliases, then the DMax() function, and so on. Isolate the point at which you have an error popping up.
This is the process to fix a query.
Oh, and please specify the precise error that is raised by Access. Also, if this is being run from VBA, please let us know because that affects your trouble-shooting.