I should I build my BQL statement to replicate this
SELECT * FROM TABLE1
WHERE TABLE1.COL1 = 'X' AND
(TABLE1.COL2 = 'Y' OR TABLE1.COL2 is null)
Thanks!
PXSelect<TABLE1,
Where<TABLE1.col1, Equal<X>,
And<Where<TABLE1.col2, Equal<Y>,
Or<TABLE1.col2, IsNull>>>>>
Related
A bit new in Acumatica, I've been tasked to update a report which it in on itself is pretty easy, just adding a new value to a filter.
The part of the query I'm modifying is:
( [INRegister].[TransferType] = '1' AND [INTran].[TranDate] BETWEEN CONVERT(DATETIME, '20220101 0:0:0.000') AND CONVERT(DATETIME, '20230112 0:0:0.000') AND ( [INRegister].[DocType] = 'I' OR [INRegister].[DocType] = 'A') AND ( [INTran].[ReasonCode] = 'Null' OR [INTran].[ReasonCode] = 'BAJACADUCA' OR [INTran].[ReasonCode] = 'INISSUED' OR [INTran].[ReasonCode] = 'Null') AND ( [InventoryItem].[PreferredVendorID] = NULL OR NULL IS NULL ))
ORDER BY [InventoryItem].[ItemClassID], [InventoryItem].[PreferredVendorID], [INTran].[TranDate] OPTION(OPTIMIZE FOR UNKNOWN)
I need to use In when ReasonCode is INISSUED because it should have another value (BAJAMERCADERIA) too but everytime I try to use the In filter the second value is ignored or truncated when I check the trace.
The second value is primarily used for the between clause. Have you tried a comma delimited list in value1? i.e. BAJAMERCADERIA,INISSUED
i want to handle dynamic query string in Arangodb
let condition = 'FILTER u.username == '+value
if(usingPhoneNumber){
condition = 'FILTER u.phoneNumber == '+value
}
const query = aql`
FOR u in users
${condition}
RETURN u
`
if I do like this, I'm getting error like
ArangoError: AQL: syntax error, unexpected bind parameter near '#value0
we can pass aql query into another aql query
let condition = aql`FILTER u.username == ${value}`
if(usingPhoneNumber){
condition = aql`FILTER u.phoneNumber == ${value}`
}
const query = aql`
FOR u in users
${condition}
RETURN u
`
this fixes my issue. thank guys for your answers
I guess your username and phone number are strings, so they must be between quotes.
let condition = 'FILTER u.username == "' + value + '"'
if(usingPhoneNumber){
condition = 'FILTER u.phoneNumber == "' + value '"'
}
const query = aql`
FOR u in users
${condition}
RETURN u
`
Could you try something like
let condition = 'FILTER u.username == ${value}'
if(usingPhoneNumber){
condition = 'FILTER u.phoneNumber == ${value}'
}
Assuming the value is getting something assigned, I feel this might work. Do let me know the error that comes up, in case it comes up.
I suggest you try adding the condition in the query.
FOR u in users
FILTER u.username ==${value0} OR u.phoneNumber == ${value0}
RETURN u
If this works for you, I supose the problem is the aql formater assumes all inserted values with ${} are bind parameters, wich will be iterated over and not a constant query declaration.
Your current script resolves to:
{
"query" : "FOR u IN users #value0 RETURN c._key",
"bindVars" : {
"value0" : "'FILTER u.username == '+value"
}
Sometimes when I refresh page the events I have sorts them DESCENDING by date, but I need ascending order by time.
http://prntscr.com/bubuz5
http://prntscr.com/bubvad
Code
public function get_frontpage_events()
{
return DB::select()->
from('events')->
where_open()->
where('frontpage', '=', 1)->
where('status', '=', 1)->
where('lang', '=', Session::instance()->get('lang'))->
where_close()->
order_by('date', 'ASC')->order_by('time', 'ASC')->
execute()->
as_array();
}
You query looks fine.
I don't know if you have a query log, but if you have you can check what query is executed, copy and paste it and run it yourself. The above code should create this SQL query (my guess is you are using MySQL):
SELECT * FROM `events` WHERE (`frontpage` = 1 AND `status` = 1 AND `lang` = 'EN') ORDER BY `date` ASC, `time` ASC
Do you do some other ordering/sorting in your view or your controller? When you loop over your results, are you sure you display all results?
The problem can be in order_by()->order_by() syntax. This method allows to use array in first argument, try this:
order_by(array('date','time'), 'ASC')
Consultant sent me this code example, here is something he expects to get
SELECT m1~vbeln_im m1~vbelp_im m1~mblnr smbln
INTO CORRESPONDING FIELDS OF TABLE lt_mseg
FROM mseg AS m1
INNER JOIN mseg AS m2 ON m1~mblnr = m2~smbln
AND m1~mjahr = m2~sjahr
AND m1~zeile = m2~smblp
FOR ALL ENTRIES IN lt_vbfa
WHERE
AND m2~bwart = '102'
AND 0 = ( select SUM( ( CASE
when SHKZG = 'S' THEN 1
when SHKZG = 'H' THEN -1
else 0
END ) *MENGE ) MENGE
into lt_mseg-summ
from mseg
where
VBELN_IM = m1~vbeln_im
and VBELP_IM = m1~vbelp_im
).
The problem is I don't see how that should work in current syntax. I think about deriving internal select and using it as condition to main one, but is there a proper way to write this nested construction?
As i get it, if nested statement = 0, then main query executes. The problem here is the case inside nested statement. Is it even possible in ABAP? And in my opinion this check could be used outside from main SQL query.
Any suggestions are welcome.
the logic that you were given is part of Native/Open SQL and has some shortcomings that you need to be aware of.
the statement you are showing has to be placed between EXEC SQL and ENDEXEC.
the logic is platform dependent.
there is no syntax checking performed between the EXEC and ENDEXEC
the execution of this bypasses the database buffering process, so its slower
To me, I would investigate a better way to capture the data that performs better outside of open/native sql.
If you want to move forward with this type of logic, below are a couple of links which should be helpful. There is an example select using a nested select with a case statement.
Test Program
Example Logic
This is probably what you need, it works at least since ABAP 750.
SELECT vbeln UP TO 100 ROWS
FROM vbfa
INTO TABLE #DATA(lt_vbfa).
DATA(rt_vbeln) = VALUE range_vbeln_va_tab( FOR GROUPS val OF <line> IN lt_vbfa GROUP BY ( low = <line>-vbeln ) WITHOUT MEMBERS ( sign = 'I' option = 'EQ' low = val-low ) ).
SELECT m1~vbeln_im, m1~vbelp_im, m1~mblnr, m2~smbln
INTO TABLE #DATA(lt_mseg)
FROM mseg AS m1
JOIN mseg AS m2
ON m1~mblnr = m2~smbln
AND m1~mjahr = m2~sjahr
AND m1~zeile = m2~smblp
WHERE m2~bwart = '102'
AND m1~vbeln_im IN ( SELECT vbelv FROM vbfa WHERE vbelv IN #rt_vbeln )
GROUP BY m1~vbeln_im, m1~vbelp_im, m1~mblnr, m2~smbln
HAVING SUM( CASE m1~shkzg WHEN 'H' THEN 1 WHEN 'S' THEN -1 ELSE 0 END * m1~menge ) = 0.
Yes, aggregating and FOR ALL ENTRIES is impossible in one SELECT, but you can trick the system with range and subquery. Also you don't need three joins for summarizing reversed docs, your SUM subquery is redundant here.
If you need to select documents not only by delivery number but also by position this will be more complicated for sure.
I am new to Adf and i have got a requirement. I have a VO(VO1) which has a View Accessor(PVA) for linking another VO(VO2).
This VO2 is related to flex fields(I am not completely aware of it). But it has something to do with code_combinations table.
Now this view accessor is having a bind variable called 'Bind_ExtraWhereClause' which is of type 'String' and has the following groovy expression in it:
"\${COMBINATION_TABLE}.ACCOUNT_TYPE = 'L' AND \${COMBINATION_TABLE}.SUMMARY_FLAG != 'Y' AND \${COMBINATION_TABLE}.DETAIL_POSTING_ALLOWED_FLAG = 'Y' AND \${COMBINATION_TABLE}.ENABLED_FLAG = 'Y'"
This expression is used for validation purpose.
I don't know exact point during runtime when this view accessor is getting executed. Now i need to change the above bind variable groovy expression to this "\${COMBINATION_TABLE}.SUMMARY_FLAG != 'Y' AND \${COMBINATION_TABLE}.DETAIL_POSTING_ALLOWED_FLAG = 'Y' AND \${COMBINATION_TABLE}.ENABLED_FLAG = 'Y'" based on a condition in my code.
How can i achieve that?
I have already tried to implement the following two methods:
1) created a transient attribute in VO1 called checkflag of type string and setting this checkflag in my code to either of following values "YES" or "NO". then i edited the bind variable groovy expression like this:
checkflag!="YES"?return "\${COMBINATION_TABLE}.ACCOUNT_TYPE = 'L' AND \${COMBINATION_TABLE}.SUMMARY_FLAG != 'Y' AND \${COMBINATION_TABLE}.DETAIL_POSTING_ALLOWED_FLAG = 'Y' AND \${COMBINATION_TABLE}.ENABLED_FLAG = 'Y'":return "\${COMBINATION_TABLE}.SUMMARY_FLAG != 'Y' AND \${COMBINATION_TABLE}.DETAIL_POSTING_ALLOWED_FLAG = 'Y' AND \${COMBINATION_TABLE}.ENABLED_FLAG = 'Y'"
so when checkflag is "NO", it takes first condition and when its "YES", it takes the second condition.
2)I cleared the Bind_ExtraWhereClause value from the VA and tried to populate it from VOROWIMPL in the getPVA() method as follows:
public RowSet getPVA(){
RowSet rs = (RowSet)getAttributeInternal(PVA);
if("NO".equals(checkflag)){ rs.setNameWhereClauseParam("Bind_ExtraWhereClause","\${COMBINATION_TABLE}.ACCOUT_TYPE = 'L' AND \${COMBINATION_TABLE}.SUMMARY_FLAG != 'Y' AND \${COMBINATION_TABLE}.DETAIL_POSTING_ALLOWED_FLAG = 'Y' AND \${COMBINATION_TABLE}.ENABLED_FLAG = 'Y'");}
else{rs.setNameWhereClauseParam("Bind_ExtraWhereClause","\${COMBINATION_TABLE}.SUMMARY_FLAG != 'Y' AND \${COMBINATION_TABLE}.DETAIL_POSTING_ALLOWED_FLAG = 'Y' AND \${COMBINATION_TABLE}.ENABLED_FLAG = 'Y'");}
rs.executeQuery();
return rs;
}
Unfortunately, both the approaches didn't help me.
I am not sure I understand 100% what are you trying to achieve, but it looks like you need a dynamic view link condition.
Instead of trying to change the view link expression, use instead a transient field in VO1, but this time use an SQL Expression as Default Value.
You need to start thinking about it differently: instead of making your view link dynamic, move the dynamic logic on Query level - by using SQL Calculated attributes.