IDEMPIERE-4178 Replace NVL with Coalesce

This commit is contained in:
hengsin 2020-02-21 09:54:57 +08:00
parent 378ea5f94b
commit 2c639f7a69
22 changed files with 130 additions and 60 deletions

View File

@ -0,0 +1,30 @@
-- IDEMPIERE-4178 Replace NVL with Coalesce
CREATE or REPLACE FUNCTION nvl (anyelement, anyelement ) RETURNS anyelement
LANGUAGE plpgsql
IMMUTABLE
AS $function$
BEGIN
RETURN coalesce($1, $2);
END;
$function$
;
CREATE or REPLACE FUNCTION nvl (numeric, integer ) RETURNS numeric
LANGUAGE plpgsql
IMMUTABLE
AS $function$
BEGIN
RETURN nvl($1, $2::numeric);
END;
$function$
;
CREATE or REPLACE FUNCTION nvl (integer, numeric ) RETURNS numeric
LANGUAGE plpgsql
IMMUTABLE
AS $function$
BEGIN
RETURN nvl($1::numeric, $2);
END;
$function$
;

View File

@ -0,0 +1,7 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- IDEMPIERE-4178 Replace NVL with Coalesce
-- PostgreSQL only
SELECT register_migration_script('202002211000_IDEMPIERE-4178.sql') FROM dual
;

View File

@ -0,0 +1,33 @@
-- IDEMPIERE-4178 Replace NVL with Coalesce
CREATE or REPLACE FUNCTION nvl (anyelement, anyelement ) RETURNS anyelement
LANGUAGE plpgsql
IMMUTABLE
AS $function$
BEGIN
RETURN coalesce($1, $2);
END;
$function$
;
CREATE or REPLACE FUNCTION nvl (numeric, integer ) RETURNS numeric
LANGUAGE plpgsql
IMMUTABLE
AS $function$
BEGIN
RETURN nvl($1, $2::numeric);
END;
$function$
;
CREATE or REPLACE FUNCTION nvl (integer, numeric ) RETURNS numeric
LANGUAGE plpgsql
IMMUTABLE
AS $function$
BEGIN
RETURN nvl($1::numeric, $2);
END;
$function$
;
SELECT register_migration_script('202002211000_IDEMPIERE-4178.sql') FROM dual
;

View File

@ -321,7 +321,7 @@ public class ImportInventory extends SvrProcess implements ImportProcess
// Excluding quantities
sql = new StringBuilder ("UPDATE I_Inventory ")
.append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Excluding quantities, ' ")
.append("WHERE NVL(QtyInternalUse,0)<>0 AND (NVL(QtyCount,0)<>0 OR NVL(QtyBook,0)<>0) ")
.append("WHERE COALESCE(QtyInternalUse,0)<>0 AND (COALESCE(QtyCount,0)<>0 OR COALESCE(QtyBook,0)<>0) ")
.append(" AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (), get_TrxName());
if (no != 0)
@ -330,7 +330,7 @@ public class ImportInventory extends SvrProcess implements ImportProcess
// Required charge for internal use
sql = new StringBuilder ("UPDATE I_Inventory ")
.append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Required charge, ' ")
.append("WHERE NVL(QtyInternalUse,0)<>0 AND NVL(C_Charge_ID,0)=0 ")
.append("WHERE COALESCE(QtyInternalUse,0)<>0 AND COALESCE(C_Charge_ID,0)=0 ")
.append(" AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (), get_TrxName());
if (no != 0)

View File

@ -201,7 +201,7 @@ public class InventoryValue extends SvrProcess
// Adjust for Valuation Date
sql = new StringBuilder("UPDATE T_InventoryValue iv ")
.append("SET QtyOnHand=")
.append("(SELECT iv.QtyOnHand - NVL(SUM(t.MovementQty), 0) ")
.append("(SELECT iv.QtyOnHand - COALESCE(SUM(t.MovementQty), 0) ")
.append("FROM M_Transaction t")
.append(" INNER JOIN M_Locator l ON (t.M_Locator_ID=l.M_Locator_ID) ")
.append("WHERE t.M_Product_ID=iv.M_Product_ID")
@ -215,7 +215,7 @@ public class InventoryValue extends SvrProcess
//
sql = new StringBuilder("UPDATE T_InventoryValue iv ")
.append("SET QtyOnHand=")
.append("(SELECT iv.QtyOnHand - NVL(SUM(t.MovementQty), 0) ")
.append("(SELECT iv.QtyOnHand - COALESCE(SUM(t.MovementQty), 0) ")
.append("FROM M_Transaction t")
.append(" INNER JOIN M_Locator l ON (t.M_Locator_ID=l.M_Locator_ID) ")
.append("WHERE t.M_Product_ID=iv.M_Product_ID")

View File

@ -141,8 +141,8 @@ public class SynchronizeTerminology extends SvrProcess
+" WHERE EXISTS (SELECT 1 FROM AD_ELEMENT e "
+" WHERE c.AD_Element_ID=e.AD_Element_ID"
+" AND (c.ColumnName <> e.ColumnName OR c.Name <> e.Name "
+" OR NVL(c.Description,' ') <> NVL(e.Description,' ') OR NVL(c.Help,' ') <> NVL(e.Help,' ')"
+" OR NVL(c.Placeholder,' ') <> NVL(e.Placeholder,' ')))";
+" OR COALESCE(c.Description,' ') <> COALESCE(e.Description,' ') OR COALESCE(c.Help,' ') <> COALESCE(e.Help,' ')"
+" OR COALESCE(c.Placeholder,' ') <> COALESCE(e.Placeholder,' ')))";
no = DB.executeUpdate(sql, false, get_TrxName());
if (log.isLoggable(Level.INFO)) log.info(" rows updated: "+no);
trx.commit(true);
@ -158,8 +158,8 @@ public class SynchronizeTerminology extends SvrProcess
+" AND EXISTS (SELECT 1 FROM AD_ELEMENT e "
+" WHERE c.AD_Element_ID=e.AD_Element_ID"
+" AND (c.ColumnName <> e.ColumnName OR c.Name <> e.Name "
+" OR NVL(c.Description,' ') <> NVL(e.Description,' ') OR NVL(c.Help,' ') <> NVL(e.Help,' ')"
+" OR NVL(c.Placeholder,' ') <> NVL(e.Placeholder,' ')))";
+" OR COALESCE(c.Description,' ') <> COALESCE(e.Description,' ') OR COALESCE(c.Help,' ') <> COALESCE(e.Help,' ')"
+" OR COALESCE(c.Placeholder,' ') <> COALESCE(e.Placeholder,' ')))";
no = DB.executeUpdate(sql, false, get_TrxName());
if (log.isLoggable(Level.INFO)) log.info(" rows updated: "+no);
trx.commit(true);
@ -176,8 +176,8 @@ public class SynchronizeTerminology extends SvrProcess
+" AND EXISTS (SELECT 1 FROM AD_ELEMENT e, AD_COLUMN c"
+" WHERE f.AD_Column_ID=c.AD_Column_ID"
+" AND c.AD_Element_ID=e.AD_Element_ID AND c.AD_Process_ID IS NULL"
+" AND (f.Name <> e.Name OR NVL(f.Description,' ') <> NVL(e.Description,' ') OR NVL(f.Help,' ') <> NVL(e.Help,' ')"
+" OR NVL(f.Placeholder,' ') <> NVL(e.Placeholder,' ')))";
+" AND (f.Name <> e.Name OR COALESCE(f.Description,' ') <> COALESCE(e.Description,' ') OR COALESCE(f.Help,' ') <> COALESCE(e.Help,' ')"
+" OR COALESCE(f.Placeholder,' ') <> COALESCE(e.Placeholder,' ')))";
no = DB.executeUpdate(sql, false, get_TrxName());
if (log.isLoggable(Level.INFO)) log.info(" rows updated: "+no);
trx.commit(true);
@ -207,8 +207,8 @@ public class SynchronizeTerminology extends SvrProcess
+" AND c.AD_Element_ID=e.AD_Element_ID AND c.AD_Process_ID IS NULL"
+" AND trl.AD_LANGUAGE=e.AD_LANGUAGE"
+" AND f.IsCentrallyMaintained='Y' AND f.IsActive='Y'"
+" AND (trl.Name <> e.Name OR NVL(trl.Description,' ') <> NVL(e.Description,' ') OR NVL(trl.Help,' ') <> NVL(e.Help,' ')"
+" OR NVL(trl.Placeholder,' ') <> NVL(e.Placeholder,' ')))";
+" AND (trl.Name <> e.Name OR COALESCE(trl.Description,' ') <> COALESCE(e.Description,' ') OR COALESCE(trl.Help,' ') <> COALESCE(e.Help,' ')"
+" OR COALESCE(trl.Placeholder,' ') <> COALESCE(e.Placeholder,' ')))";
no = DB.executeUpdate(sql, false, get_TrxName());
if (log.isLoggable(Level.INFO)) log.info(" rows updated: "+no);
trx.commit(true);
@ -227,7 +227,7 @@ public class SynchronizeTerminology extends SvrProcess
+" AND EXISTS (SELECT 1 FROM AD_ELEMENT e, AD_COLUMN c"
+" WHERE f.AD_Column_ID=c.AD_Column_ID"
+" AND c.AD_Element_ID=e.AD_Element_ID AND c.AD_Process_ID IS NULL"
+" AND (f.Name <> e.PO_Name OR NVL(f.Description,' ') <> NVL(e.PO_Description,' ') OR NVL(f.Help,' ') <> NVL(e.PO_Help,' '))"
+" AND (f.Name <> e.PO_Name OR COALESCE(f.Description,' ') <> COALESCE(e.PO_Description,' ') OR COALESCE(f.Help,' ') <> COALESCE(e.PO_Help,' '))"
+" AND e.PO_Name IS NOT NULL)"
+" AND EXISTS (SELECT 1 FROM AD_TAB t, AD_WINDOW w"
+" WHERE f.AD_Tab_ID=t.AD_Tab_ID"
@ -259,7 +259,7 @@ public class SynchronizeTerminology extends SvrProcess
+" AND c.AD_Element_ID=e.AD_Element_ID AND c.AD_Process_ID IS NULL"
+" AND trl.AD_LANGUAGE=e.AD_LANGUAGE"
+" AND f.IsCentrallyMaintained='Y' AND f.IsActive='Y'"
+" AND (trl.Name <> e.PO_Name OR NVL(trl.Description,' ') <> NVL(e.PO_Description,' ') OR NVL(trl.Help,' ') <> NVL(e.PO_Help,' '))"
+" AND (trl.Name <> e.PO_Name OR COALESCE(trl.Description,' ') <> COALESCE(e.PO_Description,' ') OR COALESCE(trl.Help,' ') <> COALESCE(e.PO_Help,' '))"
+" AND e.PO_Name IS NOT NULL)"
+" AND EXISTS (SELECT 1 FROM AD_FIELD f, AD_TAB t, AD_WINDOW w"
+" WHERE trl.AD_Field_ID=f.AD_Field_ID"
@ -283,7 +283,7 @@ public class SynchronizeTerminology extends SvrProcess
+" WHERE f.IsCentrallyMaintained='Y' AND f.IsActive='Y'"
+" AND EXISTS (SELECT 1 FROM AD_PROCESS p, AD_COLUMN c"
+" WHERE c.AD_Process_ID=p.AD_Process_ID AND f.AD_Column_ID=c.AD_Column_ID"
+" AND (f.Name<>p.Name OR NVL(f.Description,' ')<>NVL(p.Description,' ') OR NVL(f.Help,' ')<>NVL(p.Help,' ')))";
+" AND (f.Name<>p.Name OR COALESCE(f.Description,' ')<>COALESCE(p.Description,' ') OR COALESCE(f.Help,' ')<>COALESCE(p.Help,' ')))";
no = DB.executeUpdate(sql, false, get_TrxName());
if (log.isLoggable(Level.INFO)) log.info(" rows updated: "+no);
trx.commit(true);
@ -308,7 +308,7 @@ public class SynchronizeTerminology extends SvrProcess
+" WHERE c.AD_Process_ID=p.AD_Process_ID AND f.AD_Column_ID=c.AD_Column_ID"
+" AND f.AD_Field_ID=trl.AD_Field_ID AND p.AD_LANGUAGE=trl.AD_LANGUAGE"
+" AND f.IsCentrallyMaintained='Y' AND f.IsActive='Y'"
+" AND (trl.Name<>p.Name OR NVL(trl.Description,' ')<>NVL(p.Description,' ') OR NVL(trl.Help,' ')<>NVL(p.Help,' ')))";
+" AND (trl.Name<>p.Name OR COALESCE(trl.Description,' ')<>COALESCE(p.Description,' ') OR COALESCE(trl.Help,' ')<>COALESCE(p.Help,' ')))";
no = DB.executeUpdate(sql, false, get_TrxName());
if (log.isLoggable(Level.INFO)) log.info(" rows updated: "+no);
trx.commit(true);
@ -350,7 +350,7 @@ public class SynchronizeTerminology extends SvrProcess
+" WHERE f.IsCentrallyMaintained='Y' AND f.IsActive='Y'"
+" AND EXISTS (SELECT 1 FROM AD_ELEMENT e"
+" WHERE e.ColumnName=f.ColumnName"
+" AND (f.Name <> e.Name OR NVL(f.Description,' ') <> NVL(e.Description,' ') OR NVL(f.Help,' ') <> NVL(e.Help,' ') OR NVL(f.Placeholder,' ') <> NVL(e.Placeholder,' ')))";
+" AND (f.Name <> e.Name OR COALESCE(f.Description,' ') <> COALESCE(e.Description,' ') OR COALESCE(f.Help,' ') <> COALESCE(e.Help,' ') OR COALESCE(f.Placeholder,' ') <> COALESCE(e.Placeholder,' ')))";
no = DB.executeUpdate(sql, false, get_TrxName());
if (log.isLoggable(Level.INFO)) log.info(" rows updated: "+no);
trx.commit(true);
@ -378,7 +378,7 @@ public class SynchronizeTerminology extends SvrProcess
+" WHERE et.AD_LANGUAGE=trl.AD_LANGUAGE AND et.AD_Element_ID=e.AD_Element_ID"
+" AND e.ColumnName=f.ColumnName AND f.AD_Process_Para_ID=trl.AD_Process_Para_ID"
+" AND f.IsCentrallyMaintained='Y' AND f.IsActive='Y'"
+" AND (trl.Name <> et.Name OR NVL(trl.Description,' ') <> NVL(et.Description,' ') OR NVL(trl.Help,' ') <> NVL(et.Help,' ') OR NVL(trl.Placeholder,' ') <> NVL(et.Placeholder,' ')))";
+" AND (trl.Name <> et.Name OR COALESCE(trl.Description,' ') <> COALESCE(et.Description,' ') OR COALESCE(trl.Help,' ') <> COALESCE(et.Help,' ') OR COALESCE(trl.Placeholder,' ') <> COALESCE(et.Placeholder,' ')))";
no = DB.executeUpdate(sql, false, get_TrxName());
if (log.isLoggable(Level.INFO)) log.info(" rows updated: "+no);
trx.commit(true);
@ -406,7 +406,7 @@ public class SynchronizeTerminology extends SvrProcess
+" WHERE et.AD_LANGUAGE=trl.AD_LANGUAGE AND et.AD_Element_ID=e.AD_Element_ID"
+" AND e.ColumnName=f.ColumnName AND f.AD_InfoColumn_ID=trl.AD_InfoColumn_ID"
+" AND f.IsCentrallyMaintained='Y' AND f.IsActive='Y'"
+" AND (trl.Name <> et.Name OR NVL(trl.Description,' ') <> NVL(et.Description,' ') OR NVL(trl.Help,' ') <> NVL(et.Help,' ') OR NVL(trl.Placeholder,' ') <> NVL(et.Placeholder,' ')))";
+" AND (trl.Name <> et.Name OR COALESCE(trl.Description,' ') <> COALESCE(et.Description,' ') OR COALESCE(trl.Help,' ') <> COALESCE(et.Help,' ') OR COALESCE(trl.Placeholder,' ') <> COALESCE(et.Placeholder,' ')))";
no = DB.executeUpdate(sql, false, get_TrxName());
if (log.isLoggable(Level.INFO)) log.info(" rows updated: "+no);
trx.commit(true);
@ -423,7 +423,7 @@ public class SynchronizeTerminology extends SvrProcess
+" WHERE n.IsCentrallyMaintained = 'Y'"
+" AND EXISTS (SELECT 1 FROM AD_WINDOW w"
+" WHERE w.AD_Window_ID=n.AD_Window_ID"
+" AND (w.Name <> n.Name OR NVL(w.Description,' ') <> NVL(n.Description,' ') OR NVL(w.Help,' ') <> NVL("
+" AND (w.Name <> n.Name OR COALESCE(w.Description,' ') <> COALESCE(n.Description,' ') OR COALESCE(w.Help,' ') <> COALESCE("
+ (DB.isOracle() ? "dbms_lob.substr(n.Help, 4000, 1 )" : "n.Help")
+",' ')))";
no = DB.executeUpdate(sql, false, get_TrxName());
@ -445,9 +445,9 @@ public class SynchronizeTerminology extends SvrProcess
+" WHERE EXISTS (SELECT 1 FROM AD_WINDOW_TRL t, AD_WF_NODE n"
+" WHERE trl.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Window_ID=t.AD_Window_ID"
+" AND trl.AD_LANGUAGE=t.AD_LANGUAGE AND n.IsCentrallyMaintained='Y' AND n.IsActive='Y'"
+" AND (trl.Name <> t.Name OR NVL(trl.Description,' ') <> NVL(t.Description,' ') OR NVL("
+" AND (trl.Name <> t.Name OR COALESCE(trl.Description,' ') <> COALESCE(t.Description,' ') OR COALESCE("
+ (DB.isOracle() ? "dbms_lob.substr(trl.Help, 4000, 1 )" : "trl.Help")
+",' ') <> NVL(t.Help,' ')))";
+",' ') <> COALESCE(t.Help,' ')))";
no = DB.executeUpdate(sql, false, get_TrxName());
if (log.isLoggable(Level.INFO)) log.info(" rows updated: "+no);
trx.commit(true);
@ -461,7 +461,7 @@ public class SynchronizeTerminology extends SvrProcess
+" WHERE n.IsCentrallyMaintained = 'Y'"
+" AND EXISTS (SELECT 1 FROM AD_FORM f"
+" WHERE f.AD_Form_ID=n.AD_Form_ID"
+" AND (f.Name <> n.Name OR NVL(f.Description,' ') <> NVL(n.Description,' ') OR NVL(f.Help,' ') <> NVL("
+" AND (f.Name <> n.Name OR COALESCE(f.Description,' ') <> COALESCE(n.Description,' ') OR COALESCE(f.Help,' ') <> COALESCE("
+ (DB.isOracle() ? "dbms_lob.substr(n.Help, 4000, 1 )" : "n.Help")
+",' ')))";
no = DB.executeUpdate(sql, false, get_TrxName());
@ -478,9 +478,9 @@ public class SynchronizeTerminology extends SvrProcess
+" WHERE EXISTS (SELECT 1 FROM AD_FORM_TRL t, AD_WF_NODE n"
+" WHERE trl.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Form_ID=t.AD_Form_ID"
+" AND trl.AD_LANGUAGE=t.AD_LANGUAGE AND n.IsCentrallyMaintained='Y' AND n.IsActive='Y'"
+" AND (trl.Name <> t.Name OR NVL(trl.Description,' ') <> NVL(t.Description,' ') OR NVL("
+" AND (trl.Name <> t.Name OR COALESCE(trl.Description,' ') <> COALESCE(t.Description,' ') OR COALESCE("
+ (DB.isOracle() ? "dbms_lob.substr(trl.Help, 4000, 1 )" : "trl.Help")
+",' ') <> NVL(t.Help,' ')))";
+",' ') <> COALESCE(t.Help,' ')))";
no = DB.executeUpdate(sql, false, get_TrxName());
if (log.isLoggable(Level.INFO)) log.info(" rows updated: "+no);
trx.commit(true);
@ -494,7 +494,7 @@ public class SynchronizeTerminology extends SvrProcess
+" WHERE n.IsCentrallyMaintained = 'Y'"
+" AND EXISTS (SELECT 1 FROM AD_PROCESS f"
+" WHERE f.AD_Process_ID=n.AD_Process_ID"
+" AND (f.Name <> n.Name OR NVL(f.Description,' ') <> NVL(n.Description,' ') OR NVL(f.Help,' ') <> NVL("
+" AND (f.Name <> n.Name OR COALESCE(f.Description,' ') <> COALESCE(n.Description,' ') OR COALESCE(f.Help,' ') <> COALESCE("
+ (DB.isOracle() ? "dbms_lob.substr(n.Help, 4000, 1 )" : "n.Help")
+",' ')))";
no = DB.executeUpdate(sql, false, get_TrxName());
@ -511,9 +511,9 @@ public class SynchronizeTerminology extends SvrProcess
+" WHERE EXISTS (SELECT 1 FROM AD_PROCESS_TRL t, AD_WF_NODE n"
+" WHERE trl.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Process_ID=t.AD_Process_ID"
+" AND trl.AD_LANGUAGE=t.AD_LANGUAGE AND n.IsCentrallyMaintained='Y' AND n.IsActive='Y'"
+" AND (trl.Name <> t.Name OR NVL(trl.Description,' ') <> NVL(t.Description,' ') OR NVL("
+" AND (trl.Name <> t.Name OR COALESCE(trl.Description,' ') <> COALESCE(t.Description,' ') OR COALESCE("
+ (DB.isOracle() ? "dbms_lob.substr(trl.Help, 4000, 1 )" : "trl.Help")
+",' ') <> NVL(t.Help,' ')))";
+",' ') <> COALESCE(t.Help,' ')))";
no = DB.executeUpdate(sql, false, get_TrxName());
if (log.isLoggable(Level.INFO)) log.info(" rows updated: "+no);
trx.commit(true);

View File

@ -68,7 +68,7 @@ public class TransactionXRef extends SvrProcess
//
if (p_Search_InOut_ID != 0){
StringBuilder msgtrx = new StringBuilder(
"SELECT NVL(ma.M_AttributeSetInstance_ID,iol.M_AttributeSetInstance_ID) ")
"SELECT COALESCE(ma.M_AttributeSetInstance_ID,iol.M_AttributeSetInstance_ID) ")
.append("FROM M_InOutLine iol")
.append(" LEFT OUTER JOIN M_InOutLineMA ma ON (iol.M_InOutLine_ID=ma.M_InOutLine_ID) ")
.append("WHERE M_InOut_ID=").append(p_Search_InOut_ID);
@ -76,7 +76,7 @@ public class TransactionXRef extends SvrProcess
}
else if (p_Search_Order_ID != 0){
StringBuilder msgtrx = new StringBuilder(
"SELECT NVL(ma.M_AttributeSetInstance_ID,iol.M_AttributeSetInstance_ID) ")
"SELECT COALESCE(ma.M_AttributeSetInstance_ID,iol.M_AttributeSetInstance_ID) ")
.append("FROM M_InOutLine iol")
.append(" LEFT OUTER JOIN M_InOutLineMA ma ON (iol.M_InOutLine_ID=ma.M_InOutLine_ID) ")
.append(" INNER JOIN M_InOut io ON (iol.M_InOut_ID=io.M_InOut_ID)")
@ -85,7 +85,7 @@ public class TransactionXRef extends SvrProcess
}
else if (p_Search_Invoice_ID != 0){
StringBuilder msgtrx = new StringBuilder(
"SELECT NVL(ma.M_AttributeSetInstance_ID,iol.M_AttributeSetInstance_ID) ")
"SELECT COALESCE(ma.M_AttributeSetInstance_ID,iol.M_AttributeSetInstance_ID) ")
.append("FROM M_InOutLine iol")
.append(" LEFT OUTER JOIN M_InOutLineMA ma ON (iol.M_InOutLine_ID=ma.M_InOutLine_ID) ")
.append(" INNER JOIN C_InvoiceLine il ON (iol.M_InOutLine_ID=il.M_InOutLine_ID) ")

View File

@ -1808,7 +1808,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
Object[] arguments = new Object[3];
boolean filled = false;
//
String sql = "SELECT COUNT(*), NVL(SUM(LineNetAmt),0), NVL(SUM(LineTotalAmt),0) "
String sql = "SELECT COUNT(*), COALESCE(SUM(LineNetAmt),0), COALESCE(SUM(LineTotalAmt),0) "
+ "FROM C_InvoiceBatchLine "
+ "WHERE C_InvoiceBatch_ID=? AND IsActive='Y'";
//

View File

@ -190,7 +190,7 @@ public class MBOMProduct extends X_M_BOMProduct
// Set Line Number
if (getLine() == 0)
{
String sql = "SELECT NVL(MAX(Line),0)+10 FROM M_BOMProduct WHERE M_BOM_ID=?";
String sql = "SELECT COALESCE(MAX(Line),0)+10 FROM M_BOMProduct WHERE M_BOM_ID=?";
int ii = DB.getSQLValue (get_TrxName(), sql, getM_BOM_ID());
setLine (ii);
}

View File

@ -345,7 +345,7 @@ public class MDunningRunLine extends X_C_DunningRunLine
{
// we do not count the fee line as an item, but it sum it up.
StringBuilder sql = new StringBuilder("UPDATE C_DunningRunEntry e ")
.append("SET Amt=NVL((SELECT SUM(ConvertedAmt)+SUM(FeeAmt)+SUM(InterestAmt)")
.append("SET Amt=COALESCE((SELECT SUM(ConvertedAmt)+SUM(FeeAmt)+SUM(InterestAmt)")
.append(" FROM C_DunningRunLine l ")
.append("WHERE e.C_DunningRunEntry_ID=l.C_DunningRunEntry_ID), 0), ")
.append("QTY=(SELECT COUNT(*)")

View File

@ -112,7 +112,7 @@ public class MInvoiceBatchLine extends X_C_InvoiceBatchLine
if (success)
{
StringBuilder sql = new StringBuilder("UPDATE C_InvoiceBatch h ")
.append("SET DocumentAmt = NVL((SELECT SUM(LineTotalAmt) FROM C_InvoiceBatchLine l ")
.append("SET DocumentAmt = COALESCE((SELECT SUM(LineTotalAmt) FROM C_InvoiceBatchLine l ")
.append("WHERE h.C_InvoiceBatch_ID=l.C_InvoiceBatch_ID AND l.IsActive='Y'),0) ")
.append("WHERE C_InvoiceBatch_ID=").append(getC_InvoiceBatch_ID());
DB.executeUpdate(sql.toString(), get_TrxName());

View File

@ -260,7 +260,7 @@ public class MLanguage extends X_AD_Language
int AD_Language_ID = getAD_Language_ID();
if (AD_Language_ID == 0)
{
String sql = "SELECT NVL(MAX(AD_Language_ID), 999999) FROM AD_Language WHERE AD_Language_ID > 1000";
String sql = "SELECT COALESCE(MAX(AD_Language_ID), 999999) FROM AD_Language WHERE AD_Language_ID > 1000";
AD_Language_ID = DB.getSQLValue (get_TrxName(), sql);
setAD_Language_ID(AD_Language_ID+1);
}

View File

@ -500,9 +500,9 @@ public class MLookupFactory
if (KeyColumn.endsWith("_ID"))
realSQL.append("NULL,");
if (isValueDisplayed)
realSQL.append("NVL(").append(TableName).append(".Value,'-1') || '-' || ");
realSQL.append("COALESCE(").append(TableName).append(".Value,'-1') || '-' || ");
if (displayColumnSQL != null && displayColumnSQL.trim().length() > 0)
realSQL.append("NVL(").append(displayColumnSQL).append(",'-1')");
realSQL.append("COALESCE(").append(displayColumnSQL).append(",'-1')");
else {
if (showID) {
StringBuilder displayColumn = getDisplayColumn(language, TableName, list);
@ -510,7 +510,7 @@ public class MLookupFactory
realSQL.append(displayColumn);
} else {
lookupDisplayColumn = DisplayColumn;
realSQL.append("NVL(").append(TableName).append("_Trl.").append(DisplayColumn).append(",'-1')");
realSQL.append("COALESCE(").append(TableName).append("_Trl.").append(DisplayColumn).append(",'-1')");
}
}
realSQL.append(",").append(TableName).append(".IsActive");
@ -528,9 +528,9 @@ public class MLookupFactory
if (KeyColumn.endsWith("_ID"))
realSQL.append("NULL,");
if (isValueDisplayed)
realSQL.append("NVL(").append(TableName).append(".Value,'-1') || '-' || ");
realSQL.append("COALESCE(").append(TableName).append(".Value,'-1') || '-' || ");
if (displayColumnSQL != null && displayColumnSQL.trim().length() > 0)
realSQL.append("NVL(").append(displayColumnSQL).append(",'-1')");
realSQL.append("COALESCE(").append(displayColumnSQL).append(",'-1')");
else {
if (showID) {
StringBuilder displayColumn = getDisplayColumn(language, TableName, list);
@ -538,7 +538,7 @@ public class MLookupFactory
realSQL.append(displayColumn);
} else {
lookupDisplayColumn = DisplayColumn;
realSQL.append("NVL(").append(TableName).append(".").append(DisplayColumn).append(",'-1')");
realSQL.append("COALESCE(").append(TableName).append(".").append(DisplayColumn).append(",'-1')");
}
}
realSQL.append(",").append(TableName).append(".IsActive");
@ -847,7 +847,7 @@ public class MLookupFactory
StringBuilder msg = new StringBuilder().append(TableName).append(".").append(ldc.ColumnName);
String columnSQL = ldc.IsVirtual ? ldc.ColumnSQL : msg.toString();
displayColumn.append("NVL(");
displayColumn.append("COALESCE(");
// translated
if (ldc.IsTranslated && !Env.isBaseLanguage(language, TableName) && !ldc.IsVirtual

View File

@ -140,7 +140,7 @@ public class MRecentItem extends X_AD_RecentItem
}
//
MRecentItem retValue = null;
String sql = "SELECT * FROM AD_RecentItem WHERE AD_Table_ID=? AND Record_ID=? AND NVL(AD_User_ID,0)=?";
String sql = "SELECT * FROM AD_RecentItem WHERE AD_Table_ID=? AND Record_ID=? AND COALESCE(AD_User_ID,0)=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
@ -239,10 +239,10 @@ public class MRecentItem extends X_AD_RecentItem
int maxri = MSysConfig.getIntValue(MSysConfig.RecentItems_MaxSaved, 50, AD_Client_ID);
if (maxri < 0)
maxri = 0;
int cntri = DB.getSQLValue(null, "SELECT COUNT(*) FROM AD_RecentItem WHERE NVL(AD_User_ID,0)=? AND AD_Client_ID=?", AD_User_ID, AD_Client_ID);
int cntri = DB.getSQLValue(null, "SELECT COUNT(*) FROM AD_RecentItem WHERE COALESCE(AD_User_ID,0)=? AND AD_Client_ID=?", AD_User_ID, AD_Client_ID);
if (cntri > maxri) {
int cntdel = cntri - maxri;
String sql = "SELECT AD_Table_ID, Record_ID FROM AD_RecentItem WHERE NVL(AD_User_ID,0)=? AND AD_Client_ID=? ORDER BY Updated";
String sql = "SELECT AD_Table_ID, Record_ID FROM AD_RecentItem WHERE COALESCE(AD_User_ID,0)=? AND AD_Client_ID=? ORDER BY Updated";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
@ -282,7 +282,7 @@ public class MRecentItem extends X_AD_RecentItem
}
public static List<MRecentItem> getFromUser(Properties ctx, int AD_User_ID) {
int[] ids = new Query(ctx, MRecentItem.Table_Name, "NVL(AD_User_ID,0)=?", null)
int[] ids = new Query(ctx, MRecentItem.Table_Name, "COALESCE(AD_User_ID,0)=?", null)
.setOnlyActiveRecords(true)
.setClient_ID()
.setParameters(AD_User_ID)

View File

@ -139,7 +139,7 @@ public class ServerProcessCtl implements Runnable {
//
String sql = "SELECT p.Name, p.ProcedureName,p.ClassName, p.AD_Process_ID," // 1..4
+ " p.isReport,p.IsDirectPrint,p.AD_ReportView_ID,p.AD_Workflow_ID," // 5..8
+ " CASE WHEN COALESCE(p.Statistic_Count,0)=0 THEN 0 ELSE p.Statistic_Seconds/p.Statistic_Count END CASE," // 9
+ " CASE WHEN COALESCE(p.Statistic_Count,0)=0 THEN 0 ELSE p.Statistic_Seconds/p.Statistic_Count END," // 9
+ " p.IsServerProcess, p.JasperReport, p.AD_Process_UU " // 10..12
+ "FROM AD_Process p"
+ " INNER JOIN AD_PInstance i ON (p.AD_Process_ID=i.AD_Process_ID) "
@ -148,7 +148,7 @@ public class ServerProcessCtl implements Runnable {
if (!Env.isBaseLanguage(Env.getCtx(), "AD_Process"))
sql = "SELECT t.Name, p.ProcedureName,p.ClassName, p.AD_Process_ID," // 1..4
+ " p.isReport, p.IsDirectPrint,p.AD_ReportView_ID,p.AD_Workflow_ID," // 5..8
+ " CASE WHEN COALESCE(p.Statistic_Count,0)=0 THEN 0 ELSE p.Statistic_Seconds/p.Statistic_Count END CASE," // 9
+ " CASE WHEN COALESCE(p.Statistic_Count,0)=0 THEN 0 ELSE p.Statistic_Seconds/p.Statistic_Count END," // 9
+ " p.IsServerProcess, p.JasperReport, p.AD_Process_UU " // 10..12
+ "FROM AD_Process p"
+ " INNER JOIN AD_PInstance i ON (p.AD_Process_ID=i.AD_Process_ID) "

View File

@ -59,7 +59,7 @@ public class CopyFromCashPlan extends SvrProcess {
throw new IllegalArgumentException ("Source Cash Plan does not exist");
int insertNo = 0;
int lineNo = DB.getSQLValue(get_TrxName(), "SELECT NVL(MAX(Line),0)+10 FROM C_CashPlanLine WHERE C_CashPlan_ID=?", p_C_CashPlanTarget_ID);
int lineNo = DB.getSQLValue(get_TrxName(), "SELECT COALESCE(MAX(Line),0)+10 FROM C_CashPlanLine WHERE C_CashPlan_ID=?", p_C_CashPlanTarget_ID);
for (MCashPlanLine cpls : cpsource.getLines()) {
MCashPlanLine cplt = new MCashPlanLine(getCtx(), 0, get_TrxName());

View File

@ -129,7 +129,7 @@ public class GeneratePeriodicCashPlanLines extends SvrProcess {
throw new IllegalArgumentException ("Cash Plan does not exist");
int insertNo = 0;
int lineNo = DB.getSQLValue(get_TrxName(), "SELECT NVL(MAX(Line),0)+10 FROM C_CashPlanLine WHERE C_CashPlan_ID=?", p_C_CashPlan_ID);
int lineNo = DB.getSQLValue(get_TrxName(), "SELECT COALESCE(MAX(Line),0)+10 FROM C_CashPlanLine WHERE C_CashPlan_ID=?", p_C_CashPlan_ID);
for (int cnt = 0; cnt < p_Repetitions; cnt++) {
MCashPlanLine cpl = new MCashPlanLine(getCtx(), 0, get_TrxName());

View File

@ -338,7 +338,7 @@ public class ImportFixedAsset extends SvrProcess
int cnt_ok = 0;
int cnt_err = 0;
String whereClause = "NVL(I_IsImported,'N')='N'"+sqlCheck;
String whereClause = "COALESCE(I_IsImported,'N')='N'"+sqlCheck;
POResultSet<X_I_FixedAsset>
rs = new Query(getCtx(), X_I_FixedAsset.Table_Name, whereClause, get_TrxName())
.scroll();

View File

@ -104,7 +104,7 @@ public final class UserPreference implements Serializable {
*/
public void savePreference() {
if (m_AD_User_ID >= 0) {
Query query = new Query(Env.getCtx(), I_AD_Preference.Table_Name, "NVL(AD_User_ID,0) = ? AND Attribute = ? AND AD_Window_ID Is NULL AND AD_Process_ID IS NULL AND PreferenceFor = 'W'", null);
Query query = new Query(Env.getCtx(), I_AD_Preference.Table_Name, "COALESCE(AD_User_ID,0) = ? AND Attribute = ? AND AD_Window_ID Is NULL AND AD_Process_ID IS NULL AND PreferenceFor = 'W'", null);
for (int i = 0; i < PROPERTIES.length; i++) {
String attribute = PROPERTIES[i];
String value = props.getProperty(attribute);
@ -134,7 +134,7 @@ public final class UserPreference implements Serializable {
m_AD_User_ID = AD_User_ID;
props = new Properties();
Query query = new Query(Env.getCtx(), I_AD_Preference.Table_Name, "NVL(AD_User_ID,0) = ? AND Attribute = ? AND AD_Window_ID Is NULL AND AD_Process_ID IS NULL AND PreferenceFor = 'W'", null);
Query query = new Query(Env.getCtx(), I_AD_Preference.Table_Name, "COALESCE(AD_User_ID,0) = ? AND Attribute = ? AND AD_Window_ID Is NULL AND AD_Process_ID IS NULL AND PreferenceFor = 'W'", null);
for (int i = 0; i < PROPERTIES.length; i++) {
String attribute = PROPERTIES[i];

View File

@ -300,7 +300,7 @@ public class Match
m_qtyColumn = "lin.QtyInvoiced";
m_sql.append("SELECT hdr.C_Invoice_ID,hdr.DocumentNo, hdr.DateInvoiced, bp.Name,hdr.C_BPartner_ID,"
+ " lin.Line,lin.C_InvoiceLine_ID, p.Name,lin.M_Product_ID,"
+ " CASE WHEN dt.DocBaseType='APC' THEN lin.QtyInvoiced * -1 ELSE lin.QtyInvoiced END,SUM(NVL(mi.Qty,0)), org.Name, hdr.AD_Org_ID " //JAVIER
+ " CASE WHEN dt.DocBaseType='APC' THEN lin.QtyInvoiced * -1 ELSE lin.QtyInvoiced END,SUM(COALESCE(mi.Qty,0)), org.Name, hdr.AD_Org_ID " //JAVIER
+ "FROM C_Invoice hdr"
+ " INNER JOIN AD_Org org ON (hdr.AD_Org_ID=org.AD_Org_ID)" //JAVIER
+ " INNER JOIN C_BPartner bp ON (hdr.C_BPartner_ID=bp.C_BPartner_ID)"
@ -316,7 +316,7 @@ public class Match
+ " lin.Line,lin.C_InvoiceLine_ID,p.Name,lin.M_Product_ID,dt.DocBaseType,lin.QtyInvoiced, org.Name, hdr.AD_Org_ID " //JAVIER
+ "HAVING "
+ (matched ? "0" : "CASE WHEN dt.DocBaseType='APC' THEN lin.QtyInvoiced * -1 ELSE lin.QtyInvoiced END")
+ "<>SUM(NVL(mi.Qty,0))";
+ "<>SUM(COALESCE(mi.Qty,0))";
}
else if (display == MATCH_ORDER)
{
@ -361,7 +361,7 @@ public class Match
m_qtyColumn = "lin.MovementQty";
m_sql.append("SELECT hdr.M_InOut_ID,hdr.DocumentNo, hdr.MovementDate, bp.Name,hdr.C_BPartner_ID,"
+ " lin.Line,lin.M_InOutLine_ID, p.Name,lin.M_Product_ID,"
+ " lin.MovementQty,SUM(NVL(m.Qty,0)),org.Name, hdr.AD_Org_ID " //JAVIER
+ " lin.MovementQty,SUM(COALESCE(m.Qty,0)),org.Name, hdr.AD_Org_ID " //JAVIER
+ "FROM M_InOut hdr"
+ " INNER JOIN AD_Org org ON (hdr.AD_Org_ID=org.AD_Org_ID)" //JAVIER
+ " INNER JOIN C_BPartner bp ON (hdr.C_BPartner_ID=bp.C_BPartner_ID)"
@ -381,7 +381,7 @@ public class Match
+ " lin.Line,lin.M_InOutLine_ID,p.Name,lin.M_Product_ID,lin.MovementQty, org.Name, hdr.AD_Org_ID " //JAVIER
+ "HAVING "
+ (matched ? "0" : "lin.MovementQty")
+ "<>SUM(NVL(m.Qty,0))";
+ "<>SUM(COALESCE(m.Qty,0))";
}
// Log.trace(7, "VMatch.tableInit", m_sql + "\n" + m_groupBy);
} // tableInit

View File

@ -381,7 +381,7 @@ public abstract class CreateFromShipment extends CreateFrom
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
StringBuilder sql = new StringBuilder("SELECT " // Entered UOM
+ "l.QtyInvoiced-SUM(NVL(mi.Qty,0)),l.QtyEntered/l.QtyInvoiced,"
+ "l.QtyInvoiced-SUM(COALESCE(mi.Qty,0)),l.QtyEntered/l.QtyInvoiced,"
+ " l.C_UOM_ID,COALESCE(uom.UOMSymbol,uom.Name)," // 3..4
+ " p.M_Locator_ID, loc.Value, " // 5..6
+ " l.M_Product_ID,p.Name, po.VendorProductNo, l.C_InvoiceLine_ID,l.Line," // 7..11

View File

@ -77,7 +77,7 @@ public abstract class PaymentFormDirect extends PaymentForm {
/**
* Load Accounts
*/
String SQL = "SELECT a.C_BP_BankAccount_ID, NVL(b.Name, ' ')||'_'||NVL(a.AccountNo, ' ') AS Acct "
String SQL = "SELECT a.C_BP_BankAccount_ID, COALESCE(b.Name, ' ')||'_'||COALESCE(a.AccountNo, ' ') AS Acct "
+ "FROM C_BP_BankAccount a"
+ " LEFT OUTER JOIN C_Bank b ON (a.C_Bank_ID=b.C_Bank_ID) "
+ "WHERE C_BPartner_ID=?"