HQL with case, sum e max - java

I have a query that is giving problem, I believe the problem occurs because it does not allow to use the max function, inside the max function, am I correct?
How can I get around this? I need to add all values ​​except for the last row.
The query:
"SELECT new project.domain.vo.MediaPagVo(" +
"a.nomeUsuario, " +
"a.cpfUsuario, " +
"a.cnpjUnidadeUsuario, " +
"a.nomeUnidadeUsuario, " +
"a.codigoGrupoUsuario, " +
"a.grupo.id AS idGrupo, " +
"CASE " +
"WHEN MAX(a.pre) - MIN(a.pre) > 0 " +
"THEN ((MAX(a.pre) - MIN(a.pre)) / SUM(CASE WHEN max(a.dtRequisicao) > a.dtRequisicao THEN a.valorTotal ELSE 0 END)) " +
"ELSE ((MAX(a.pos) - MIN(a.pos)) / SUM(CASE WHEN max(a.dtRequisicao) >= a.dtRequisicao THEN a.valorTotal ELSE 0 END)) " +
"END AS mediaConsumo, " +
"CASE " +
"WHEN MAX(a.pre) - MIN(a.pre) > 0 " +
"THEN " + Tipo.PRE.getValue() + " " +
"ELSE " + Tipo.POS.getValue() + " " +
"END AS tipoPag) " +
"FROM " +
" Pagamento a " +
"WHERE " +
"a.status = " + StatusPagamento.Concluido.getValue() + " AND " +
"a.dataRequisicao BETWEEN :inicio and :fim AND " +
"( :idGrupo IS NULL OR a.grupo.id = :idGrupo) " +
"GROUP BY " +
" a.nomeUsuario, a.cpfUsuario, a.cnpjUnidadeUsuario, a.nomeUnidadeUsuario, a.codigoGrupoUsuario, a.grupo.id, " +
"HAVING (MAX(a.pos) - MIN(a.pos) > 0 OR MAX(a.pre) - MIN(a.pre) > 0) AND " +
"( :tipoConsumo IS NULL OR " +
":tipoConsumo = " + Tipo.PRE.getValue() + " AND " +
"(MAX(a.pre) - MIN(a.pre) > 0) " +
"OR :tipoConsumo = " + Tipo.POS.getValue() + " AND " +
"(MAX(a.pos) - MIN(a.pos) > 0) ) ";
The error began to occur after I modified this section, adding the case inside the sum:
"CASE WHEN MAX(a.pre) - MIN(a.pre) > 0 " +
"THEN ((MAX(a.pre) - MIN(a.pre)) / SUM(CASE WHEN max(a.dtRequisicao) > a.dtRequisicao THEN a.valorTotal ELSE 0 END)) " +
"ELSE ((MAX(a.pos) - MIN(a.pos)) / SUM(CASE WHEN max(a.dtRequisicao) >= a.dtRequisicao THEN a.valorTotal ELSE 0 END)) " +
"END AS mediaPag, "
The error returned by java:
Could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
ORA-00937: not a single-group group function tips
My goal was to add up all the payments for that period, minus the last. Unfortunately, I could not just move the filter, since max (a.pre), max (a.pos) may be the last payment. Does anyone have any ideas?

Maybe it is also worth asking how to refactor this query. Is performance a problem? I mean instead of running one query you would run several smaller ones would the system be very slow.
For ex. get MIN MAX(a.pre) in a separate query, do the SUM(CASE WHEN in Java code and pass these values as parameters.
If you decide to refactor, it would be safe to first add some tests to see the behaviour of the old query with certain values. Then do the refactoring. And finally, re-run the tests you added to check that you didn't add any bug.

Related

How to create stored function from Spring using JdbcTemplate?

For administration needs, I need to create and replace stored procedures from Spring Repository. Has anyone already done this?
I tried to use following code(unfinished):
#Component
public class JdbcRepository {
#Autowired
private JdbcTemplate jdbc;
public void checkConn(){
jdbc.execute("create or replace package Z$CLIENT_INTERFACE_API as \n" +
" function CL_ORG_SEARCH_CREATE(p_request in clob) return clob;\n" +
"end Z$CLIENT_INTERFACE_API;\n" +
"/\n" +
"create or replace package body Z$CLIENT_INTERFACE_API as\n" +
" function CL_ORG_SEARCH_CREATE(p_request in clob) return clob\n" +
" is\n" +
" content_xml VARCHAR2(4000);\n" +
" p Dbms_Xmlparser.Parser;\n" +
" v_Doc Dbms_Xmldom.Domdocument;\n" +
" v_Root_Element Dbms_Xmldom.Domelement;\n" +
" v_Child_Nodes Dbms_Xmldom.Domnodelist;\n" +
" v_Child_Node Dbms_Xmldom.Domnode;\n" +
" v_Message_Id VARCHAR2(36);\n" +
" v_First_Char VARCHAR2(1);\n" +
" begin\n" +
" content_xml:= CAST(p_request as VARCHAR2);\n" +
" p := Dbms_Xmlparser.Newparser;\n" +
" dbms_xmlparser.setvalidationmode(p,False);\n" +
" dbms_xmlparser.parsebuffer(p,content_xml);\n" +
" v_Doc := dbms_xmlparser.getdocument(p);\n" +
" v_Root_Element := Dbms_Xmldom.getdocumentelement(v_Doc);\n" +
" return 'aaaaaaaaaaaaaaaaaaaaaaaaaa1';\n" +
" end;\n" +
"end Z$CLIENT_INTERFACE_API;\n" +
"/");
}
}
But whan I execute it, i take broken package in db. In same time, whan I run this from SQLDeveloper - all works perfect.
You are separating statements by both semicolon ; and slash /.
Try using only one of those, but not both. If that doesn't work either, try executing each statement separately with execute( )
This works perfect:
jdbc.execute("create or replace package Z$CLIENT_INTERFACE_API as \n" +
" function CL_ORG_SEARCH_CREATE(p_request in clob) return clob;\n" +
"end Z$CLIENT_INTERFACE_API;\n");
jdbc.execute("create or replace package body Z$CLIENT_INTERFACE_API as\n" +
" function CL_ORG_SEARCH_CREATE(p_request in clob) return clob\n" +
" is\n" +
" content_xml VARCHAR2(4000);\n" +
" p Dbms_Xmlparser.Parser;\n" +
" v_Doc Dbms_Xmldom.Domdocument;\n" +
" v_Root_Element Dbms_Xmldom.Domelement;\n" +
" v_Child_Nodes Dbms_Xmldom.Domnodelist;\n" +
" v_Child_Node Dbms_Xmldom.Domnode;\n" +
" v_Message_Id VARCHAR2(36);\n" +
" v_First_Char VARCHAR2(1);\n" +
" begin\n" +
" content_xml:= CAST(p_request as VARCHAR2);\n" +
" p := Dbms_Xmlparser.Newparser;\n" +
" dbms_xmlparser.setvalidationmode(p,False);\n" +
" dbms_xmlparser.parsebuffer(p,content_xml);\n" +
" v_Doc := dbms_xmlparser.getdocument(p);\n" +
" v_Root_Element := Dbms_Xmldom.getdocumentelement(v_Doc);\n" +
" return 'aaaaaaaaaaaaaaaaaaaaaaaaaa1';\n" +
" end;\n" +
"end Z$CLIENT_INTERFACE_API;");

create a java process to generate a idempiere report

I have Postgres that works when on it own, but doesn't work when integrated into java and called on idempiere. I'm looking for suggestion.
I get the ff error:
caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "00"
Position: 1055; State=42601; ErrorCode=0
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)
at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:120)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:384)
at jdk.internal.reflect.GeneratedMethodAccessor48.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.compiere.db.StatementProxy.invoke(StatementProxy.java:130)
at com.sun.proxy.$Proxy11.executeUpdate(Unknown Source)
at org.compiere.util.DB.executeUpdate(DB.java:1039)
at org.compiere.util.DB.executeUpdate(DB.java:898)
at org.compiere.util.DB.executeUpdate(DB.java:885)
at ice.enterprise.base.report.StockAgingReport.createDetailLines(StockAgingReport.java:145)
at ice.enterprise.base.report.StockAgingReport.doIt(StockAgingReport.java:72)
at org.compiere.process.SvrProcess.process(SvrProcess.java:201)
at org.compiere.process.SvrProcess.startProcess(SvrProcess.java:147)
at org.adempiere.util.ProcessUtil.startJavaProcess(ProcessUtil.java:173)
at org.compiere.apps.AbstractProcessCtl.startProcess(AbstractProcessCtl.java:467)
at org.compiere.apps.AbstractProcessCtl.run(AbstractProcessCtl.java:235)
15:21:49.994===========> DataEngine.loadPrintData: null - ERROR: column "levelno" does not exist
Position: 924
SQL=SELECT T_ReportStockAgeing.CurrentCost,T_ReportStockAgeing.Date1,T_ReportStockAgeing_ICE.Description,T_ReportStockAgeing.OnHand,(SELECT NVL(AD_PInstance.Name,'-1') ||'_'|| NVL(CAST (AD_PInstance.AD_PInstance_ID AS Text),'-1') ||'_'|| NVL((SELECT NVL(AD_Process.Name,'-1') ||'_'|| NVL(AD_Process.Value,'-1') FROM AD_Process WHERE AD_PInstance.AD_Process_ID=AD_Process.AD_Process_ID),'-1') FROM AD_PInstance WHERE T_ReportStockAgeing.AD_PInstance_ID=AD_PInstance.AD_PInstance_ID) AS AAD_PInstance_ID,T_ReportStockAgeing.AD_PInstance_ID AS AD_PInstance_ID,T_ReportStockAgeing.ProductCode,T_ReportStockAgeing.Qty1,T_ReportStockAgeing.Qty2,T_ReportStockAgeing.Qty3,T_ReportStockAgeing.Qty4,T_ReportStockAgeing.Value1,T_ReportStockAgeing.Valu2,T_ReportStockAgeing.Value3,T_ReportStockAgeing.Value4,T_ReportStockAgeing_ICE.T_ReportStockAgeing_ICE_UU,LevelNo FROM T_ReportStockAgeing_ICE WHERE T_ReportStockAgeing_ICE.AD_PInstance_ID=2109500 [136]
15:21:50.030===========> AbstractProcessDialog.doRun: org.postgresql.util.PSQLException: ERROR: column "levelno" does not exist
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.logging.Level;
import org.compiere.print.MPrintFormat;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Ini;
public class StockAgingReport extends SvrProcess {
private int p_AD_Org_ID = 0;
private int p_AD_Client_ID = 0;
private int p_C_AcctSchema_ID = 0;
private int p_M_Product_Category_ID = 0;
private Timestamp p_Date = null;
private long m_start = System.currentTimeMillis();
#Override
protected void prepare() {
StringBuffer sb = new StringBuffer ("Record_ID=")
.append(getRecord_ID());
// Parameter
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
String name = para[i].getParameterName();
if (para[i].getParameter() == null && para[i].getParameter_To() == null)
;
else if (name.equals("Date"))
{
p_Date = (Timestamp)para[i].getParameter();
}
else if (name.equals("AD_Org_ID"))
p_AD_Org_ID = ((BigDecimal)para[i].getParameter()).intValue();
else if (name.equals("AD_Client_ID"))
p_AD_Client_ID = para[i].getParameterAsInt();
else if (name.equals("C_AcctSchema_ID"))
p_C_AcctSchema_ID = para[i].getParameterAsInt();
else if (name.equals("M_Product_Category_ID"))
p_M_Product_Category_ID = para[i].getParameterAsInt();
else
log.log(Level.SEVERE, "Unknown Parameter: " + name);
}
log.fine(sb.toString());
}
#Override
protected String doIt() throws Exception {
createDetailLines();
int AD_PrintFormat_ID = DB.getSQLValue(get_TrxName(), "Select AD_PrintFormat_ID from AD_PrintFormat Where name = 'Stock_Ageing'");
if (AD_PrintFormat_ID > 0) {
if (Ini.isClient())
getProcessInfo().setTransientObject (MPrintFormat.get (getCtx(), AD_PrintFormat_ID, false));
else
getProcessInfo().setSerializableObject(MPrintFormat.get (getCtx(), AD_PrintFormat_ID, false));
}
if (log.isLoggable(Level.FINE)) log.fine((System.currentTimeMillis() - m_start) + " ms");
return "";
}
private void createDetailLines() {
StringBuffer sb = new StringBuffer ("INSERT INTO T_ReportStockAgeing "
+ "(AD_PInstance_ID, AD_Client_ID, AD_Org_ID, ProductCode, Description, CurrentCost,"
+ " Qty1, Qty2, Qty3, Qty4, OnHand,"
+ " Value1, Valu2, Value3 ,Value4) ");
sb.append("SELECT ").append(getAD_PInstance_ID()).append(", ").append(Env.getAD_Client_ID(getCtx())).append(", ").append(Env.getAD_Org_ID(getCtx())).append(", ")
.append( "ProductCode, Description, Case OnHand WHEN 0 THEN 0 ELSE CurrentCost*OnHand END AS CurrentCost,"
+ "Qty1, Qty2, Qty3, Qty4, OnHand,"
+ "CASE OnHand WHEN 0 THEN 0 ELSE round((CurrentCost) * Qty1,2) END as Value1, "
+ "CASE OnHand WHEN 0 THEN 0 ELSE round((CurrentCost) * Qty2,2) END as Valu2, "
+ "CASE OnHand WHEN 0 THEN 0 ELSE round((CurrentCost) * Qty3,2) END as Value3, "
+ "CASE OnHand WHEN 0 THEN 0 ELSE round((CurrentCost) * Qty4,2) END as Value4 "
+ "FROM ( "
+ "SELECT "
+ "prod.value as ProductCode, "
+ "prod.description as Description, "
+ "M_Product_Category_ID, "
+ "(SELECT COALESCE (max(c.CurrentCostPrice),0) FROM M_Cost c WHERE c.AD_Org_ID =" +p_AD_Org_ID +" AND c.C_AcctSchema_ID= "+p_C_AcctSchema_ID+" AND prod.M_Product_ID = c.M_Product_ID AND prod.ProductType !='A' ) as CurrentCost, "
+ "(SELECT COALESCE (SUM (st.qtyonhand),0)FROM M_Storage st "
+ "WHERE prod.M_Product_ID = st.M_Product_ID "
+ "AND st.DateMaterialPolicy >= ( ("+p_Date+"::date) - interval '3 month' ) "
+ "AND st.DateMaterialPolicy <= ("+p_Date+"::date) "
+ "AND st.AD_Org_ID = "+p_AD_Org_ID+" AND prod.ProductType !='A' "
+ ") as Qty1, "
+ "(SELECT COALESCE (SUM (st.qtyonhand),0)FROM M_Storage st "
+ "WHERE prod.M_Product_ID = st.M_Product_ID "
+ "AND st.DateMaterialPolicy >= ("+p_Date+"::date- interval '6 month' ) "
+ "AND st.DateMaterialPolicy <= ("+p_Date+"::date - interval '3 month') "
+ "AND st.AD_Org_ID = "+p_AD_Org_ID+" AND prod.ProductType !='A') "
+ "as Qty2, "
+ "(SELECT COALESCE (SUM (st.qtyonhand),0)FROM M_Storage st "
+ "WHERE prod.M_Product_ID = st.M_Product_ID "
+ "AND st.DateMaterialPolicy >= ("+p_Date+"::date - interval '12 month' ) "
+ "AND st.DateMaterialPolicy <= ("+p_Date+"::date- interval '6 month') "
+ "AND st.AD_Org_ID = "+p_AD_Org_ID+" AND prod.ProductType !='A' "
+ ") as Qty3, "
+ "(SELECT COALESCE (SUM (st.qtyonhand),0)FROM M_Storage st "
+ "WHERE prod.M_Product_ID = st.M_Product_ID "
+ "AND st.DateMaterialPolicy < ("+p_Date+"::date- interval '12 month') "
+ "AND st.AD_Org_ID = "+p_AD_Org_ID+" AND prod.ProductType !='A' "
+ ") as Qty4, "
+ "(SELECT COALESCE (SUM (st.qtyonhand),0)FROM M_Storage st "
+ "WHERE prod.M_Product_ID = st.M_Product_ID "
+ "AND st.AD_Org_ID = "+p_AD_Org_ID+" AND prod.ProductType !='A' "
+ ") as OnHand "
+ "FROM M_Product prod "
+ "LEFT JOIN AD_Org org ON org.AD_Org_ID = "+p_AD_Org_ID+" "
+ "LEFT JOIN M_Product_Category prodcat ON prodcat.M_Product_Category_ID = "+p_M_Product_Category_ID+" AND prodcat.AD_Client_ID = "+p_AD_Client_ID+" "
+ "WHERE prod.M_Product_Category_ID = "+ p_M_Product_Category_ID+" AND prod.ProductType !='A' "
+ ")temp ");
sb.append(" ) as temp ");
int no = DB.executeUpdate(sb.toString(), get_TrxName());
log.fine("#" + no);
log.finest(sb.toString());
}
}
I tried to integrate your class example for testing in iDempiere, but as GhostCat pointed, it's better if you create a minimal reproducible example, and also very important, please post also the error that is being thrown by the system, in UI and/or in console log.
The class doesn't have some imports, all the variables are not used, and the private method createDetailLines is never called, I assume the error you're mentioning is in that method, but there is no way to know if is not called.
Now, reviewing the SQL, there are two things to notice:
1 - it's not formatted for java, you use "AND c.C_AcctSchema_ID= $P{C_AcctSchema_ID}" and that's not the way as java manage variables, that sounds like jasper report syntax instead of java. For JDBC you must use ? as a replacement for binding variables
2 - iDempiere is multi-database, the way how the system is designed is to write oracle compatible SQL syntax, and there is a translation layer that converts the oracle statement ot postgresql syntax. So, it's better to avoid using postgresql specific syntax like "::date" or interval '3 month' - it could work, but it can also have problems with the convert layer. If you want to use specific postgresql syntax and avoid the convert layer being confused you can surround the postgresql specific syntax with NATIVE_PostgreSQL_KEYWORK - please don't blame me about the error in this constant :-)

convert split to_char statement from Oracle to SQL Server in Java

I have some Oracle SQL statements in my java code which is often split in singular parts which makes in difficult for me to find an equivalent statement in SQL Server 2017. Here is an example:
if (typeId >= 1 && typeId <= 5)
{
sql = "SELECT t.run_id, t.tran_id, t.tran_id sort_id, t.tran_type, t.prod_id, t.type_id, t.value, " +
getExtractStatement() + " (year from t.tran_datetime) y, " +
getExtractStatement() + " (month from t.tran_datetime) mo, " +
getExtractStatement() + " (day from t.tran_datetime) d, " +
" to_number(to_char (t.tran_datetime, 'HH24')) h, " +
" to_number(to_char (t.tran_datetime, 'MI')) mi, " +
" to_number(to_char (t.tran_datetime, 'SS')) s, " +
" to_number(to_char (t.tran_datetime, 'FF')) ms " +
" FROM tran_calc_group t, mai_group_log m " +
" WHERE t.run_id = m.run_id and m.group_id = 1 " +
" AND m.mai_class_id = %d " +
" AND t.result_group_id = m.level_1 " +
" AND t.result_group_id_2 = m.level_2 " +
" AND t.result_group_id_3 = m.level_3 " +
" AND t.result_group_id_4 = m.level_4 " +
" AND t.prod_id = " + query.getProdId() +
" AND t.run_id IN (" + runLogIds + ")" +
" AND t.type_id = " + typeId;
}
If it were only a usual to_char statement with a YYYY-MM-DD argument for example I could just use GETDATE(), 20 in SQL Server but I don't know how to do this for such a split statement
" to_number(to_char (t.tran_datetime, 'HH24')) h, " +
" to_number(to_char (t.tran_datetime, 'MI')) mi, " +
" to_number(to_char (t.tran_datetime, 'SS')) s, " +
" to_number(to_char (t.tran_datetime, 'FF')) ms " +
I have tried to convert it with a tool (SQLines) but it did not work.
You can check the DATEPART function in SQL Server. It allows you to extract particular parts of given date and time value. For example:
SELECT GETUTCDATE()
,DATEPART(HOUR, GETUTCDATE())
,DATEPART(MINUTE, GETUTCDATE())
,DATEPART(SECOND, GETUTCDATE())
,DATEPART(MILLISECOND, GETUTCDATE());
Also, as stated in the documentation, it returns integer, so there is no need for additional converting.

How to write prepared statements for this query?

Hi i have written a join query for my app and its working. My next requirement is to convert that query to prepared statement where I am stuck.
"SELECT * FROM " + TableA.TABLE + " as d LEFT JOIN " + TableB.TABLE + " as c ON d."+ TableA.DAMAGECODE + "=c." + TableB.DAMAGECODE + " AND d."
+ TableA.INDEX + "=c." + TableB.DAMAGECODEINDEX + " AND d."
+ TableA.OBJECTTYPE + "=c." + TableB.OBJECTCLASS + " WHERE d."+ TableA.LEAF + " = '1' AND d." + TableA.OBJECTTYPE + " = ? AND " + "(d."+ TableA.DAMAGECODE + " LIKE ? OR d." + TableA.DAMAGETEXT + " LIKE ?) AND c." + TableB.CONSTRUCTIONSERIES + " = ? ORDER BY " + TableA.DAMAGETEXT;
cursor = db.rawQuery(sql,new String[]{String.valueOf(objectClass),"'%" + query + "%'","'%" + query + "%'",constructionSeries});
When i ran raw query i am getting results ,but when ran the above prepared statements i am getting cursor count always zero
You don't need to add the ' yourself when you pass a String parameters, the PreparedStatement will manage those itself.
"'%" + query + "%'"
For the moment you have condition like
where columnA = "'%somethingToFind%'"
So unless you have a value in columnA like 'somethingToFindInColumnA' (note the quote at the begin and the end of that String). You will never get a result.
Remove those to get something like :
"%" + query + "%"
Full answer :
db.rawQuery(sql,new String[]{String.valueOf(objectClass),"'%" + query + "%'","'%" + query + "%'",constructionSeries});
Become :
db.rawQuery(sql,new String[]{String.valueOf(objectClass),"%" + query + "%","%" + query + "%",constructionSeries});

JDBC query returning zero when using simple arithmetic operations and alias even though the data in table is not zero

I am building a web portal through android and a query i am running through JDBC drivers is returning 0 where data should not be zero.
This is the query:
ResultSet set = statement.executeQuery("select it.itcod, it.itnam, it.packn, it.tradp, " +
"sum(nvl(itd.slbox,0) - nvl(itd.srbox,0) - nvl(itd.brbox,0) - nvl(itd.gsbox,0)) as sbox, " +
"sum(nvl(itd.slbbx,0) - nvl(itd.srbbx,0) - nvl(itd.brbbx,0) - nvl(itd.gsbbx,0)) as sbbx, " +
"SUM(NVL(itd.PRBOX,0) - NVL(itd.RPBOX,0) - NVL(itd.TRBOX,0)) as pbox, " +
"SUM(NVL(itd.PRBBX,0) - NVL(itd.RPBBX,0) - NVL(itd.TRBBX,0)) as pbbx " +
"from items it " +
"LEFT join item_daily itd " +
"on (it.cocod = itd.cocod " +
"and it.itcod = itd.itcod " +
"and ITD.ddate between " + fdate + " and " + tdate + ")" +
"WHERE IT.COCOD = " + COCOD +
"AND IT.DCODE = " + DCODE +
"AND NVL(IT.FREZE,'N')!='Y' " +
"group by it.cocod, it.itcod, it.itnam, it.packn, " +
" it.tradp, it.pkqty, it.dcode, it.freze, " +
" it.ishow, it.sltax, it.dcont, it.mcode, " +
" it.nwcod " +
"order by itnam ");
I have tried using resultsetmetadata but that does not work either.
you should be careful to this line
+ fdate + " and " + tdate
because you should use like this:
" .. to_date('"+fdate+"','***your_date_format') and to_date('"+fdate+"','***your_date_format')"

Categories