Help analyzing a single query perfomance
Hi,
we're using MaxDB 7.7 in a large e-commerce project.
Recently we're having performances issues and I'm trying to understand what's the problem.
This is the query
select articolo2_.ID as col_0_0_, articolo2_.CODICE as col_1_0_, articolo2_.CODICEREPOSITORY as col_2_0_, articolo2_.DESCRIZIONE as col_3_0_, marchio5_.NOME as col_4_0_, articolo2_.MODELLO as col_5_0_, categoria6_.NOME as col_6_0_, unitamisur7_.DESCRIZIONE as col_7_0_, articoloco1_.ID as col_8_0_, articoloco1_.CODICE as col_9_0_, articoloco1_.STATOCOMMERCIALE as col_10_0_, articoloco1_.DATA_STATOCOMMERCIALE as col_11_0_, articolo2_.ALTRO1 as col_12_0_, articolo2_.ALTRO2 as col_13_0_, articolo2_.ALTRO3 as col_14_0_, articolo2_.ALTRO4 as col_15_0_, articolo2_.ALTRO5 as col_16_0_, articoloco1_.ATTIVO as col_17_0_, articoloco1_.LOTTOORDINE as col_18_0_, articoloco1_.MINIMOORDINE as col_19_0_, articoloco1_.SCORTAMINIMA as col_20_0_, MIN(prezzo0_.PREZZO) as col_21_0_, SUM(dispmagazz4_.DISPONIBILITA) as col_22_0_, SUM(dispmagazz4_.DISPFUTURA) as col_23_0_, iva8_.CODICE as col_24_0_, iva8_.PERC as col_25_0_, articolo2_.STIMAPESO as col_26_0_, MAX(prezzo0_.FLAG) as col_27_0_, articolo2_.COMPOSTO as col_28_0_, articoloco1_.ELEMENTO_ARTICOLOCOMPOSTO as col_29_0_, articoloco1_.DATA_CREAZIONE as col_30_0_, articoloco1_.DATA_ULTIMAMODIFICA as col_31_0_, MIN(prezzo0_.PREZZOPREC) as col_32_0_, MIN(prezzo0_.DATAPREZZOPREC) as col_33_0_, MIN(prezzo0_.PREZZOPRECNOFLAG) as col_34_0_, articolo2_.ALTEZ as col_35_0_, articolo2_.LARG as col_36_0_, articolo2_.PROF as col_37_0_, articolo2_.TAGLIA as col_38_0_, articolo2_.COLORE as col_39_0_, articolo2_.TIPOMISURE as col_40_0_, articolo2_.STIMACOLLI as col_41_0_, articolo2_.KEYWORDS as col_42_0_, MIN(prezzo0_.PREZZOIVATO) as col_43_0_, MIN(prezzo0_.PREZZOPRECIVATO) as col_44_0_, MIN(prezzo0_.PREZZOPRECNOFLAGIVATO) as col_45_0_, articolo2_.CODSTRUTTURAVARIANTE as col_46_0_, articolo2_.VARIANTE1 as col_47_0_, articolo2_.VARIANTE2 as col_48_0_, articolo2_.VARIANTE3 as col_49_0_, articolo2_.VARIANTE4 as col_50_0_, articolo2_.VARIANTE5 as col_51_0_, articolo2_.VARIANTE6 as col_52_0_, articolo2_.VARIANTE7 as col_53_0_, articolo2_.VARIANTE8 as col_54_0_, articolo2_.CARATTERISTICA1 as col_55_0_, articolo2_.CARATTERISTICA2 as col_56_0_, articolo2_.CARATTERISTICA3 as col_57_0_, articolo2_.CARATTERISTICA4 as col_58_0_, articolo2_.CARATTERISTICA5 as col_59_0_, MIN(articolifo3_.ID_PUNTOPARTENZA) as col_60_0_, iva10_.CODICE as col_61_0_, iva10_.PERC as col_62_0_, articolo2_.QTACONFEZIONE as col_63_0_, articolo2_.QTACARTONE as col_64_0_, articolo2_.QTABANCALE as col_65_0_
from ECF3.PREZZO prezzo0_, ECF3.ARTICOLO_COMMERCIALE articoloco1_, ECF3.ARTICOLO articolo2_, ECF3.ARTICOLO_FORNITORE articolifo3_, ECF3.MARCHIO marchio5_, ECF3.CATEGORIA categoria6_, ECF3.UNITAMISURA unitamisur7_, ECF3.IVA iva8_, ECF3.IVA iva10_, ECF3.DISPMAGAZZINO dispmagazz4_, ECF3.MACROCATEGORIA macrocateg13_, ECF3.REPARTO reparto14_
where prezzo0_.ID_ARTICOLOCOMM=articoloco1_.ID and articoloco1_.ID_ARTICOLO=articolo2_.ID and articolo2_.ID=articolifo3_.ID_ARTICOLO(+) and articolo2_.ID_MARCHIO=marchio5_.ID and articolo2_.ID_CATEGORIA=categoria6_.ID and articolo2_.ID_UM=unitamisur7_.ID and articolo2_.ID_IVA=iva8_.ID and articolo2_.ID_IVAINGROSSO=iva10_.ID and categoria6_.ID_MACROCATEGORIA=macrocateg13_.ID and macrocateg13_.ID_REPARTO=reparto14_.ID and articolifo3_.ABITUALE='S' and dispmagazz4_.ID_ARTICOLOCOMM=articoloco1_.ID and articoloco1_.ID_AZIENDA=1 and articoloco1_.ID_CANALE=9 and articoloco1_.ATTIVO='A' and prezzo0_.ID_LISTINO=47 and prezzo0_.PREZZO>0 and reparto14_.NOME='ELDOM' and (upper(articolo2_.DESCRIZIONE) like '%mp3%' or upper(articolo2_.MODELLO) like '%mp3%' or upper(articolo2_.KEYWORDS) like '%mp3%')
group by articolo2_.ID , articolo2_.CODICE , articolo2_.CODICEREPOSITORY , articolo2_.DESCRIZIONE , marchio5_.NOME , articolo2_.MODELLO , categoria6_.NOME , unitamisur7_.DESCRIZIONE , articoloco1_.ID , articoloco1_.CODICE , articoloco1_.STATOCOMMERCIALE , articoloco1_.DATA_STATOCOMMERCIALE , articolo2_.ALTRO1 , articolo2_.ALTRO2 , articolo2_.ALTRO3 , articolo2_.ALTRO4 , articolo2_.ALTRO5 , articoloco1_.ATTIVO , articoloco1_.LOTTOORDINE , articoloco1_.MINIMOORDINE , articoloco1_.SCORTAMINIMA , iva8_.CODICE , iva8_.PERC , articolo2_.STIMAPESO , articolo2_.COMPOSTO , articoloco1_.ELEMENTO_ARTICOLOCOMPOSTO , articoloco1_.DATA_CREAZIONE , articoloco1_.DATA_ULTIMAMODIFICA , articolo2_.ALTEZ , articolo2_.LARG , articolo2_.PROF , articolo2_.TAGLIA , articolo2_.COLORE , articolo2_.TIPOMISURE , articolo2_.STIMACOLLI , articolo2_.KEYWORDS , articolo2_.CODSTRUTTURAVARIANTE , articolo2_.VARIANTE1 , articolo2_.VARIANTE2 , articolo2_.VARIANTE3 , articolo2_.VARIANTE4 , articolo2_.VARIANTE5 , articolo2_.VARIANTE6 , articolo2_.VARIANTE7 , articolo2_.VARIANTE8 , articolo2_.CARATTERISTICA1 , articolo2_.CARATTERISTICA2 , articolo2_.CARATTERISTICA3 , articolo2_.CARATTERISTICA4 , articolo2_.CARATTERISTICA5 , iva10_.CODICE , iva10_.PERC , articolo2_.QTACONFEZIONE , articolo2_.QTACARTONE , articolo2_.QTABANCALE
order by MIN(prezzo0_.PREZZO) ASC
and this is the explain result
SCHEMANAME TABLENAME COLUMN_OR_INDEX STRATEGY PAGECOUNT
UNITAMISUR7_ TABLE SCAN 1
PREZZO0_ PREZZO_LISTINO_idx JOIN VIA INDEXED COLUMN 13655
ID_LISTINO (USED INDEX COLUMN)
ARTICOLOCO1_ ID JOIN VIA KEY COLUMN 5401
REPARTO14_ IDX_NOME_MONDO JOIN VIA INDEXED COLUMN 1
TABLE HASHED
NOME (USED INDEX COLUMN)
ARTICOLIFO3_ IDX_ARTICOLO_FORNITORE_ARTICOLO JOIN VIA INDEXED COLUMN 5478
ID_ARTICOLO (USED INDEX COLUMN)
ARTICOLO2_ ID JOIN VIA KEY COLUMN 8098
MARCHIO5_ ID JOIN VIA KEY COLUMN 5
TABLE HASHED
CATEGORIA6_ ID JOIN VIA KEY COLUMN 8
TABLE HASHED
IVA8_ ID JOIN VIA KEY COLUMN 1
TABLE HASHED
IVA10_ ID JOIN VIA KEY COLUMN 1
TABLE HASHED
DISPMAGAZZ4_ DISPMAGAZZINO_IDARTICOLOCOMM_IDX JOIN VIA INDEXED COLUMN 801
ID_ARTICOLOCOMM (USED INDEX COLUMN)
MACROCATEG13_ ID JOIN VIA KEY COLUMN 1
TABLE HASHED
NO TEMPORARY RESULTS CREATED
INTERNAL TEMPORARY RESULT TABLE SCAN 1
JDBC_CURSOR_54 RESULT IS COPIED , COSTVALUE IS 289903
The query takes an average of 25 seconds in working hours. It returns 611 rows. MaxDB 7.7 running on Linux, 2 processors, 4 cores each, 32GB Ram. Cache size is 4GB for this db and data size is about 5GB. Cache hit 100%.
What I'm not sure is if the query is already optimized and the problem is the workload on the server or the query can be optimized.
The query is generated by Hibernate so I really can't tweak the SQL.
Thank you for any suggestion !
Dear Lars,
thanks for your help.
I think the problem is on some joins because removing them and using an added field in place of them (de-normalyzing information) the query is much faster.
First, all the joins are backed by indexes with integer keys.
These are the tables involved (i removed the fields not related to joins for clarity), query time are not average, they're a single run times in working hours :
CREATE TABLE ECF3.ARTICOLO (
ID INTEGER NOT NULL,
DESCRIZIONE VARCHAR() ASCII(512) NOT NULL,
MODELLO VARCHAR() ASCII(100) NOT NULL,
KEYWORDS VARCHAR() ASCII(512),
ID_UM INTEGER,
ID_IVA INTEGER,
ID_IVAINGROSSO INTEGER,
ID_CATEGORIA INTEGER,
ID_MARCHIO INTEGER,
PRIMARY KEY (ID)
The table contains 115.729 rows, 4.857 rows match the search condition on this table fields, like on '%MP3%' (query runs in 0.4 sec).
CREATE TABLE ECF3.ARTICOLO_COMMERCIALE (
ID INTEGER NOT NULL,
ID_AZIENDA INTEGER,
ID_CANALE INTEGER,
ID_ARTICOLO INTEGER,
ATTIVO CHAR() ASCII(1) NOT NULL,
PRIMARY KEY (ID)
The table contains 413.916 rows, 45.086 rows match the search condition on this table field, ID_AZIENDA=1, ID_CANALE=9, ATTIVO='A' (query runs in 0.48 sec).
CREATE TABLE ECF3.ARTICOLO_FORNITORE (
ID INTEGER NOT NULL,
ABITUALE CHAR() ASCII(1),
ID_ARTICOLO INTEGER,
PRIMARY KEY (ID)
The table contains 115.503 rows, all match the search condition on this table field, ABITUALE='S' (query runs in 0.7 sec).
CREATE TABLE ECF3.PREZZO (
ID INTEGER NOT NULL,
PREZZO FIXED(14,3),
ID_LISTINO INTEGER,
ID_ARTICOLOCOMM INTEGER,
PRIMARY KEY (ID)
The table contains 2.246.518 rows, 58.396 match the search condition on this table field, ID_LISTINO=47 AND PREZZO>0 (query runs in 0.4 sec)
CREATE TABLE ECF3.DISPMAGAZZINO (
ID_MAGAZZINO INTEGER NOT NULL,
ID_ARTICOLOCOMM INTEGER NOT NULL,
PRIMARY KEY (ID_MAGAZZINO,ID_ARTICOLOCOMM)
Table contains 404.664 rows, no conditions on query, only joins with other table ARTICOLO_COMMERCIALE.
There are then the smaller tables
CREATE TABLE ECF3.REPARTO (
ID INTEGER NOT NULL,
NOME VARCHAR() ASCII(100) NOT NULL,
PRIMARY KEY (ID)
CREATE TABLE ECF3.MACROCATEGORIA (
ID INTEGER NOT NULL,
NOME VARCHAR() ASCII(100) NOT NULL,
ID_REPARTO INTEGER DEFAULT 0 NOT NULL,
PRIMARY KEY (ID)
CREATE TABLE ECF3.CATEGORIA (
ID INTEGER NOT NULL,
ID_MACROCATEGORIA INTEGER NOT NULL,
NOME VARCHAR() ASCII(100) NOT NULL,
PRIMARY KEY (ID)
This is a 'tree', reparto has only 5 rows, macrocategoria has 29 rows, categoria has 1120 rows. The search condition on reparto gets to 765 categoria rows.
CREATE TABLE ECF3.MARCHIO (
ID INTEGER NOT NULL,
NOME VARCHAR() ASCII(100) NOT NULL,
PRIMARY KEY (ID)
The table contains 1189 rows
CREATE TABLE ECF3.IVA (
ID INTEGER NOT NULL,
PRIMARY KEY (ID)
This table contains 15 rows.
CREATE TABLE ECF3.UNITAMISURA (
ID INTEGER NOT NULL,
PRIMARY KEY (ID)
This table contains 6 rows.
The CATEGORIA, MARCHIO, MACROCATEGORIA, REPARTO was added later to the structure. Before this we had a field CATEGORIA, MARCHIO, REPARTO in the ARTICOLO table.
Using the fields instead of the joins the query is fast (2 sec.). Adding these tables has slowed down to 25 sec. (15 in non working hours).
This is what I don't understand, they're small tables, I understand the joins add complexity but the time difference between the two version of the model is very high !
Thanks for help and sorry for the long post.
Similar Messages
-
Is it possible to combine 2 different reports in a single Query?
Dear All,
What am I working at?
I produced a Query for Debtors Aged Analysis which mimics the Official SAP B1 8.8 Aging Report.
It ages the outstanding invoices by Posting Date ( RefDate in JDT1)
I also made another Report which ages outstanding amounts by Document Date simply by replacing all RefDate by TaxDate
They give different answers if Posting Date is different from Document Date, e.g a manual invoice dated 5 Jun 2011 is posted on 2 Jul 2011.
What I want to do?
My idea is to produce a SINGLE QUERY which will generate either Aging depending on settings:
(a) A Debtors Aging by Posting Date
(b) A Debtors Aging by Document Date
I declare 2 variables:
(a) @refdt is [%1] and represents Posting Date (JDT1 RefDate)
(b) @taxdt is [%2] and represents Document Date (JDT1 TaxDate)
When the Query is run, the foll dialog appears:
Query - Selection Criteria
Posting Date Equal .......
Document Date Equal .......
OK Cancel
We are expected to fill in only 1 date and leave the other blank, and Query will generate the required report .
What is my problem?
Query runs smoothly, but amounts in the Balance column does not get analyzed in the Age brackets: Current / 1 Mth Ago / etc
I think I know where's the problem
I am assuming (wrongly) that if we don't fill one date field, the query returns NULL for that variable. In fact, it appears to return GetDate().
Help
Can anybody help me put the correct commands so that all my balances are correctly analysed in the respective age buckets?
Thanks
Leon Lai
Here's a simplified SQL:
Tables :
JDT1 T0 = Journal Entry - Rows
OCRD T1 = Business Partner
OCPR T2 = Contact Person
OJDT T3 = Journal Entry - Header
OINV T4 = A/R Invoices - Header
ORIN T5 - A/R Credit Memo - Header
declare @refdt date
declare @taxdt date
set @refdt
/*Select 1 from jdt1 t where t.RefDate*/ = [%1]
set @taxdt
/*Select 1 from jdt1 w where w.TaxDate*/ = [%2]
SELECT
'company1' AS 'Company',
T1.CardCode AS 'BP Code',
T2.Notes2 AS 'BP Name',
T0.RefDate AS 'Pstg Dt',
T0.TaxDate AS 'Doc Dt',
CASE
WHEN T0.TransType = 13 THEN 'IN'
WHEN T0.TransType = 14 THEN 'CN'
WHEN T0.TransType = 30 THEN 'JE'
WHEN T0.TransType = 24 THEN 'RC'
WHEN T0.TransType = 46 THEN 'PS'
ELSE 'Error ! ! !'
END AS 'Doc Type',
T0.Ref1 'Doc. Number',
ISNULL(T0.FCCurrency, ' - ') AS 'Ccy',
(T0.FCDebit - T0.FCCredit) AS 'Orig. F.Ccy',
(T0.BalFcDeb - T0.BalFcCred) AS 'Bal. F. Ccy',
(T0.Debit - T0.Credit) AS 'Orig. Rs',
(T0.BalDueDeb - T0.BalDueCred) AS 'Bal. Rs',
/* ######################## PROBLEM is here ################## */
CASE
WHEN (@refdt is not null) and (@taxdt is null)
THEN ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred
WHERE DateDiff(mm, T0.RefDate, @refdt) = 0 ) ,0)
WHEN (@refdt is null) and (@taxdt is not null)
THEN ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred
WHERE DateDiff(mm, T0.TaxDate, @taxdt) = 0 ) ,0)
END AS 'Current Mth',
CASE
WHEN (@refdt is not null) and (@taxdt is null)
THEN ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred
WHERE DateDiff(mm, T0.RefDate, @refdt) = 1 ) ,0)
WHEN (@refdt is null) and (@taxdt is not null)
THEN ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred
WHERE DateDiff(mm, T0.TaxDate, @taxdt) = 1 ) ,0)
END AS '1 Mth Ago'
/* Similarly for other age buckets */
FROM company1.dbo.JDT1 T0
INNER JOIN company1.dbo.OCRD T1 ON T0.ShortName = T1.CardCode
LEFT OUTER JOIN company1.dbo.OCPR T2 ON T1.CardCode = T2.Cardcode
LEFT OUTER JOIN company1.dbo.OJDT T3 ON T0.TransID = T3.TransID
LEFT OUTER JOIN company1.dbo.OINV T4 ON T3.TransID = T4.TransID
LEFT OUTER JOIN company1.dbo.ORIN T5 ON T3.TransID = T5.TransID
WHERE
T1.CardType = 'C' and Balance != 0
and (T0.BalDueDeb - T0.BalDueCred) != 0HI
I generate the next aged analysis
CREATE PROCEDURE [dbo].[Aged_Analysis] (@end datetime,@Client VarChar (20)) AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets
-- interfering with SELECT statements.
SET NOCOUNT ON;
Declare @SAPUNION Table (SN VarChar(50), TransId Int, ReconSum Decimal(19,2), DebHab VarChar(1),
Linea Int)
insert into @SAPUNION
SELECT X0.ShortName 'SN', X0.TransId 'TransId', SUM(X0.ReconSum)'ReconSum', X0.IsCredit 'DebHab', X0.TransRowId 'Linea'
FROM ITR1 X0
INNER JOIN OITR X1 ON X1.ReconNum = X0.ReconNum
WHERE X1.ReconDate <= @end AND X1.CancelAbs = ''
GROUP BY X0.ShortName, X0.TransId, X0.IsCredit, X0.TransRowId
SELECT T0.CardCode, T0.CardName,T0.Address,T0.CreditLine,
T1.TransId , T4.BaseRef , T1.Ref2 , T1.RefDate, T1.DueDate,
CASE
WHEN T3.DebHab = 'D' THEN T1.Debit-T1.Credit-T3.ReconSum
WHEN T3.DebHab = 'C' THEN T1.Debit-T1.Credit+T3.ReconSum
ELSE (T1.Debit-T1.Credit)
END 'Balance',
CASE
when DateDiff(Day,t1.RefDate,GetDate()) <= 30 and T3.DebHab = 'D' then T1.Debit-T1.Credit-T3.ReconSum
when DateDiff(Day,t1.RefDate,GetDate()) <= 30 and T3.DebHab = 'C' then T1.Debit-T1.Credit+T3.ReconSum
when DateDiff(Day,t1.RefDate,GetDate()) <= 30 then (T1.Debit-T1.Credit) end '0-30 dias',
CASE
when DateDiff(Day,t1.refdate,GetDate()) between 31 and 45 and T3.DebHab = 'D' then T1.Debit-T1.Credit-T3.ReconSum
when DateDiff(Day,t1.refdate,GetDate()) between 31 and 45 and T3.DebHab = 'C' then T1.Debit-T1.Credit+T3.ReconSum
when DateDiff(Day,t1.refdate,GetDate()) between 31 and 45 then (T1.Debit-T1.Credit) end '31-45 dias',
CASE
when DateDiff(Day,t1.refdate,GetDate()) between 46 and 60 and T3.DebHab = 'D' then T1.Debit-T1.Credit-T3.ReconSum
when DateDiff(Day,t1.refdate,GetDate()) between 46 and 60 and T3.DebHab = 'C' then T1.Debit-T1.Credit+T3.ReconSum
when DateDiff(Day,t1.refdate,GetDate()) between 46 and 60 then (T1.Debit-T1.Credit) end '46-60 dias',
CASE
when DateDiff(Day,t1.refdate,GetDate()) between 61 and 75 and T3.DebHab = 'D' then T1.Debit-T1.Credit-T3.ReconSum
when DateDiff(Day,t1.refdate,GetDate()) between 61 and 75 and T3.DebHab = 'C' then T1.Debit-T1.Credit+T3.ReconSum
when DateDiff(Day,t1.refdate,GetDate()) between 61 and 75 then (T1.Debit-T1.Credit) end '61-75 dias',
CASE
when DateDiff(Day,t1.refdate,GetDate()) BETWEEN 76 AND 89 and T3.DebHab = 'D' then T1.Debit-T1.Credit-T3.ReconSum
when DateDiff(Day,t1.refdate,GetDate()) BETWEEN 76 AND 89 and T3.DebHab = 'C' then T1.Debit-T1.Credit+T3.ReconSum
when DateDiff(Day,t1.refdate,GetDate()) BETWEEN 76 AND 89 then (T1.Debit-T1.Credit) end '76-89 dias',
CASE
when DateDiff(Day,t1.refdate,GetDate()) >90 and T3.DebHab = 'D' then T1.Debit-T1.Credit-T3.ReconSum
when DateDiff(Day,t1.refdate,GetDate()) >90 and T3.DebHab = 'C' then T1.Debit-T1.Credit+T3.ReconSum
when DateDiff(Day,t1.refdate,GetDate()) >90 then (T1.Debit-T1.Credit) end '90-Mas',
CASE T1.TransType
WHEN '13' THEN (SELECT Y.Comments FROM OINV Y WHERE Y.TransId = T1.TransId)
WHEN '14' THEN (SELECT Y.Comments FROM ORIN Y WHERE Y.TransId = T1.TransId)
WHEN '24' THEN (SELECT Y.Comments FROM ORCT Y WHERE Y.TransId = T1.TransId)
ELSE T1.LineMemo
END 'Comments'
FROM OCRD T0
INNER JOIN JDT1 T1 ON T1.ShortName = T0.CardCode
INNER JOIN OACT T2 ON T2.AcctCode = T1.Account
INNER JOIN OJDT T4 ON T4.TransId = T1.TransId
LEFT JOIN OINV T5 ON T5.TransId = T4.TransId and t5.ObjType = t4.TransType
LEFT JOIN @SAPUNION T3 ON T3.TransId = T1.TransId AND T3.SN = T1.ShortName AND T3.Linea = T1.Line_ID
WHERE T0.CardType = 'C' /*FOR CLIENTS*/ AND T1.RefDate <= @end AND T2.AcctCode = /*YOUR CLIENT ACCOUNT*/ AND
(CASE
WHEN T3.DebHab = 'D' THEN (T1.Debit-T1.Credit-T3.ReconSum)
WHEN T3.DebHab = 'C' THEN (T1.Debit-T1.Credit+T3.ReconSum)
ELSE (T1.Debit-T1.Credit)
END) != '0'
AND T0.CardCode= @Client
ORDER BY T0.CardCode,T1.TransId,t1.Ref2
END
AND Execute by SAP
DECLARE @VAR INT, @DATE DATETIME, @BP VARCHAR(8)
SET @VAR = (SELECT TOP 1 T.DocEntry FROM [dbo].[OINV] T WHERE T.DocDate <='[%0]' AND T.CardCode='[%1]')
SET @DATE = '[%0]'
SET @BP = '[%1]'
EXECUTE [dbo].[Aged_Analysis]
@end = @DATE,
@Client = @BP
Regards
Floyola
Edited by: Floyola on Jul 22, 2011 10:17 AM -
Multiple databases in a single query
I need to query multiple databases in a single query.
e.g.
Database d1 contains table t1 with column id
Database d2 contains table t2 with column id
I need a query like
SELECT * FROM t1, t2 WHERE t1.id = t2.id;
is this possible in jdbc? if yes can anyone help with some sample code?
thanks,
Ashish SarafIt is not possible using the JDBC API to query tables in two or more databases using a single query. The reason is that a JDBC Connection is made to a single data source.
However, some databases support the idea of federations or linked tables. What you do is inside the database manager link or federate a table that is present in another DBMS. Then, pose a single JDBC query to the one DBMS which will have its own table and links to the external tables.
Another approach is to use a special JDBC driver with a built-in integration engine that will perform a query across multiple databases. In effect, the system poses separate queries to the different databases and integrates and joins the data together for you automatically on the client-side. That is much easier than doing it yourself in code, but that is also possible for simple queries.
As part of my research program, we have released a shareware version of the UnityJDBC driver that can query multiple databases using a single SQL query. For more information, see:
http://www.unityjdbc.com
http://www.cs.uiowa.edu/~rlawrenc/research/projects.html
Sincerely,
Dr. Ramon Lawrence
Assistant Professor
Department of Computer Science
University of Iowa
[email protected] -
Populate Multiple Items bundled in a single query
Hello,
I am trying to create a report in which I have mulitple items that I want to populate. All of these use the same query but use different rows in the query to populate themselves. My question is:-
Is there a way to bundle the item assignment into a single query and populate the items from there? I want to reduce the time it takes for me to display the report and just hit the database once instead.Hi there,
when u say report, i think its a more of a page showing few items on a region whose values are populated from Database rather than a SQL report which will not have any items. Is that correct?
yes, multiple items of a page can be assigned values at once.
assume: P1_ITEM1,P1_ITEM2,P1_ITEM3,P1_ITEM4 are different items on a page, an "On-Load Before Header" PL/SQL process can be created to assign values to the items in this way:
SELECT tab.col1,tab.col2,tab.col3,tab.col4 INTO :P1_ITEM1,:P1_ITEM2,:P1_ITEM3,:P1_ITEM4 FROM TABLE tab;
Item "Source Used" should be of type: Only When Current Value in session state is null
Source Type: PL/SQL Expression or function
and Source Value or EXpression should be some thing like this :P1_ITEM1
Hope this helps.
Edited by: Chaitu_Apex on Mar 10, 2010 2:43 PM -
How to make the query in one single query? No Union please....
Hi,
I have sets of around 18 queries which is finding counts in many scenarios. I wanted to have a single query for this. which diplays the result in a single row.Is there a way , I heared analytical functions are good options ,but I am new to Oracle . Please help me.
select count(*) total_count from emp; --100
select coun(*) MGR_count from emp where job='MGR'-- 10
select count(*) dept_count from emp where deptno in(10 ,20)-- 75
output..
TOTAL_COUNT MGR_COUNT DEPT_COUNT
100 10 75
ThanksThis:
select count(*) total_Count
,count(decode(job,'MGR',1,null)) mgr_count
,count(case when deptno in (10,20) then
1
else
null
end
) dept_count
from emp;
untested -
How to calculate the individual sums of multiple columns in a single query
Hello,
Using Oracle 11gR2 on windows 7 client. I have a question on calculating sum() on multiple columns on different columns and store the results in a view. Unfortunately I could not post the problem here as it keeps on giving error "Sorry, this content is not allowed", without telling where or what it is! So I had to post it in the stack-overflow forum, here is the link: http://stackoverflow.com/questions/16529721/how-to-calculate-the-individual-sums-of-multiple-columns-in-a-single-query-ora
Will appreciate any help or suggestion.
Thanksuser13667036 wrote:
Hello,
Using Oracle 11gR2 on windows 7 client. I have a question on calculating sum() on multiple columns on different columns and store the results in a view. Unfortunately I could not post the problem here as it keeps on giving error "Sorry, this content is not allowed", without telling where or what it is! So I had to post it in the stack-overflow forum, here is the link: http://stackoverflow.com/questions/16529721/how-to-calculate-the-individual-sums-of-multiple-columns-in-a-single-query-ora
Will appreciate any help or suggestion.
ThanksLooks like you want a simple group by.
select
yr
, mnth
, region
, sum(handled_package)
, sum(expected_missing_package)
, sum(actual_missing_package)
from test
group by
yr, mnth, region
order by
yr, mnth, region;I wouldn't recommend storing your data for year / month in 2 columns like that unless you have a really good reason. I would store it as a date column and add a check constraint to ensure that the date is always the first of the month, then format it out as you wish to the client.
CREATE TABLE test
year_month date,
Region VARCHAR2(50),
CITY VARCHAR2(50),
Handled_Package NUMBER,
Expected_Missing_Package NUMBER,
Actual_Missing_Package NUMBER
alter table test add constraint firs_of_month check (year_month = trunc(year_month, 'mm'));
ME_XE?Insert into TEST (year_month, REGION, CITY, HANDLED_PACKAGE, EXPECTED_MISSING_PACKAGE, ACTUAL_MISSING_PACKAGE)
2 Values (to_date('2012-nov-12', 'yyyy-mon-dd'), 'Western', 'San Fransisco', 200, 10, 5);
Insert into TEST (year_month, REGION, CITY, HANDLED_PACKAGE, EXPECTED_MISSING_PACKAGE, ACTUAL_MISSING_PACKAGE)
ERROR at line 1:
ORA-02290: check constraint (TUBBY.FIRS_OF_MONTH) violated
Elapsed: 00:00:00.03
ME_XE?Insert into TEST (year_month, REGION, CITY, HANDLED_PACKAGE, EXPECTED_MISSING_PACKAGE, ACTUAL_MISSING_PACKAGE)
2 Values (to_date('2012-nov-01', 'yyyy-mon-dd'), 'Western', 'San Fransisco', 200, 10, 5);
1 row created.
Elapsed: 00:00:00.01
ME_XE?select
2 to_char(year_month, 'fmYYYY') as year
3 , to_char(year_month, 'fmMonth') as month
4 , Region
5 , CITY
6 , Handled_Package
7 , Expected_Missing_Package
8 , Actual_Missing_Package
9 from test;
YEAR MONTH REGION CITY HANDLED_PACKAGE EXPECTED_MISSING_PACKAGE ACTUAL_MISSING_PACKAGE
2012 November Western San Fransisco 200 10 5
1 row selected.
Elapsed: 00:00:00.01
ME_XE?Then you have nice a nice and easy validation that ensures you data integrity.
Cheers, -
How to find Special Characters in a single query
Dear Experts,
Your usual help is required to solve the query.My query is "How to find all special characters like (%$*&@,;'/+- etc. in a single query?"
Thanks.
e.g.
A_MIR
A%SIM
A*SIM
A)SIMHi,
947459 wrote:
Dear Experts,
Your usual help is required to solve the query.My query is "How to find all special characters like (%$*&@,;'/+- etc. in a single query?"
Thanks.
e.g.
A_MIR
A%SIM
A*SIM
A)SIMIt's not clear what you want.
What are "special characters"? Can you list all of them?
Do you want to find rows where string_column contains any of the special characters? If so
SELECT string_column
FROM table_x
WHERE string_column != NVL ( TRANSLATE ( string_column
, 'A(%$*&@,;'/+-'
, 'A'
, 'A'
;I assume 'A' is not a special character.
You could also use regular expressions, but it will be more efficient if you don't use them unless you really need to.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements), and the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ {message:id=9360002}
You'll get better replies sooner if you always include this information whenever you have a question. -
How to find the number of hits on a single query
how to get the information for number of hits on a single query on single day in BI system,
Regards
Kumar..Following links might help you
Re: BEx Query is executed how many times???
Number of times a Query is Run -
Hi,
I have a table with two columns as follows
child parent
mom grandma
daughter mom
How can I write a single query so that the result will be daughter,mom,grandma?
Thanks
Ravi.Responses to these postings will help:
pivot the column names
PIVOT in oracle.
Re: Pivot Query -
i have a table
source table :
create table order(name_a varchar2(100),intid number);
insert into order values('a',1);
insert into order values('b',1);
insert into order values('c',1);
insert into order values('d',1);
insert into order values('e',2);
insert into order values('f',2);
insert into order values('g',2);
i need a query , which result in the below output :
if i look for intid=1 the query should give a,b,c,d
if i look for intid=2 the query should give f,g
ThanksHi,
781649 wrote:
i have a table
source table :
create table order(name_a varchar2(100),intid number);
insert into order values('a',1);
insert into order values('b',1);
insert into order values('c',1);
insert into order values('d',1);
insert into order values('e',2);
insert into order values('f',2);
insert into order values('g',2);Thanks for posting the CREATE TABLE and INSERT statements; it's very helpful.
i need a query , which result in the below output :
if i look for intid=1 the query should give a,b,c,d
if i look for intid=2 the query should give f,gDid you mean <b>e</b>,f,g ?
That's called String Aggregation , and how to do it depends on your version of Oracle, and your exact requirements.
See thie following page for several techniques:
http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
If you're using Oracle 10 (or higher), and it's important that the name_a's be in order in the output, then you can do this:
WITH got_r_num AS
SELECT name_a
, intid
, ROW_NUMBER () OVER ( PARTITION BY intid
ORDER BY name_a
) AS r_num
FROM order_table -- ORDER is not a good table name
WHERE intid IN (1) -- Optional
SELECT intid
, SUBSTR ( SYS_CONNECT_BY_PATH (name_a, ',')
, 2
) AS name_a_list
FROM got_r_num
WHERE CONNECT_BY_ISLEAF = 1
START WITH r_num = 1
CONNECT BY r_num = PRIOR r_num + 1
AND intid = PRIOR intid
;Starting in Oracle 11.2, LISTAGG is better.
This does not assume that you are getting the output only for a single intid at a time. You can get any number of them in a suingle query. Of course, that number can be 1 if that's what you want.
Edited by: Frank Kulash on Mar 24, 2011 12:19 PM -
2 workbooks for a single query r not coming in portal.
hi experts... first of all i donno whether this question belong to bex side or portal side...
my problem is:
i have single query with 10 workbooks.
i need to embed these workbooks in our
portal(bw report iview).
my requirement is to supply URLs for all of these workbooks to portal team, so as to enable them to embed workbooks...
while im trying to generate URLs for all workbooks,
it is just generating only one same URL for all workbooks.
i found that we can generate URL only to query default view, from our BEx side..
anybody can help me that how to generate different URLs for different workbooks based on a single query.
this is not a portal issue...
i shud supply proper URLs for each workbook.
hope i can get a solution from experts...
thank u all
nithinGo through the following link
http://help.sap.com/saphelp_nw04/helpdata/en/4d/f3fa40badbf36fe10000000a1550b0/content.htm
I hope this helps.
Best Regards,
Kiran -
I have a table and cols as below:
START DATE TOTAL DAYS
10/11/2011 15:00 1
10/15/2011 5:00 1
12/22/2011 10:00 1
12/22/2011 11:00 2
12/30/2011 10:00 1
1/1/2012 1:00 1
1/1/2012 10:00 1
1/1/2012 16:00 2
1/2/2012 14:00 1
1/3/2012 15:00 1
1/4/2012 15:00 2
1/4/2012 18:00 1
I need to query where the values from the above table
should return values like below:
I tried many ways but could not find suitable solution.
Kindly help me in this regard.
START DATE TOTAL DAYS
10/11/2011 15:00 1
10/15/2011 5:00 1
12/22/2011 11:00 2
12/30/2011 10:00 1
1/1/2012 16:00 2
1/2/2012 14:00 1
1/3/2012 15:00 1
1/4/2012 15:00 2
ultimate goal is to sum up the all numbers TOTAL DAYS column in the second table... All task should be handled in single query. I cannot use java coding to handle this as my requirement needs to be included in the query which exists already.
Edited by: 915175 on Feb 16, 2012 11:02 PMselect trunc(start_date), max(start_date), max(total_days) from tablename
group by trunc(start_date);Please check below Test done at my local site with you data:
SQL>
SQL> with tablename as
2 (
3 select to_date('10/11/2011 15:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
4 select to_date('10/15/2011 5:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
5 select to_date('12/22/2011 10:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
6 select to_date('12/22/2011 11:00' , 'mm/dd/yyyy hh24:mi') start_date, 2 total_days from dual union all
7 select to_date('12/30/2011 10:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
8 select to_date('1/1/2012 1:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
9 select to_date('1/1/2012 10:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
10 select to_date('1/1/2012 16:00' , 'mm/dd/yyyy hh24:mi') start_date, 2 total_days from dual union all
11 select to_date('1/2/2012 14:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
12 select to_date('1/3/2012 15:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
13 select to_date('1/4/2012 15:00' , 'mm/dd/yyyy hh24:mi') start_date, 2 total_days from dual union all
14 select to_date('1/4/2012 18:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual
15 )
16 select TO_CHAR(max(start_date),'MM/DD/YYYY HH24:MI') start_date , max(total_days) total_days from tablename
17 group by trunc(start_date);
START_DATE TOTAL_DAYS
10/15/2011 05:00 1
01/03/2012 15:00 1
12/30/2011 10:00 1
01/01/2012 16:00 2
10/11/2011 15:00 1
12/22/2011 11:00 2
01/04/2012 18:00 2
01/02/2012 14:00 1
8 rows selected.
SQL>Regards,
Dipali..
Update: Added test done at my database..
Edited by: Dipali Vithalani on Feb 16, 2012 11:18 PM -
How to analyzer the BI query in VISUAL COMPOSER?
hi experts,
could you please explain me how to analyze the Bex query in VISUAL COMPOSER? could you please provide me the step-by-step documentation if possible??
regards
vadlamudiHi Vadlamudi,
Here is some documentation for using BI Queries in VC:
[Modeling Composite Views Using BI Data Services|http://help.sap.com/saphelp_nwce10/helpdata/en/46/081ed5f8685875e10000000a11466f/frameset.htm]
[Maintaining BI System Connections|http://help.sap.com/saphelp_nwce10/helpdata/en/7e/6dbcea3700452195e3bddaa47c5906/frameset.htm]
I hope it helps,
Regards,
Udi -
Distinct data from different columns of a table-Single query
I have a table with different columns. Each of these columns have entries. A particular column, say, a column called name can have same entries more than one time. Likewise other columns can also have same entries more than once. My requirement is to have distinct entries from each of these columns using a single query, such that , for eg; the name column will contain the name George only once on retrieval. Place column will have the place Newyork only once...like that...but Newyork and newyork should be treated different(likewise in other columns also ie; case sensitive). I want to retrieve the above said using a single query from a table. Kindly help.
Regards,
AneesYou're asking a SQL question in a JDBC forum. Look for a SQL forum. The website of the database manfactuer may have a SQL forum/mailinglist.
-
Need some help with the Select query.
Need some help with the Select query.
I had created a Z table with the following fields :
ZADS :
MANDT
VKORG
ABGRU.
I had written a select query as below :
select single vkorg abgru from ZADS into it_rej.
IT_REJ is a Work area:
DATA : BEGIN OF IT_REJ,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
This is causing performance issue. They are asking me to include the where condition for this select query.
What should be my select query here?
Please suggest....
Any suggestion will be apprecaiated!
Regards,
DeveloperHello Everybody!
Thank you for all your response!
I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
I had created a Z table with the following fields :
ZADS :
MANDT
VKORG
ABGRU.
I had written a select query as below :
I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table
select vkorg abgru from ZADS into it_rej.
Earlier :
IT_REJ is a Work area:
DATA : BEGIN OF IT_REJ,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
Now :
DATA : BEGIN OF IT_REJ occurs 0,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
I guess this will fix the issue correct?
PLease suggest!
Regards,
Developer.
Maybe you are looking for
-
Production Order For Project with plant stock
Hi, We have a scenario where in we are required to create a production order for a project. But the material(raw material) is in a storage location and is a stock item. Even the header material is also a stock item and it to stored in the storage loc
-
Email address in submit to button
I'm asking a very direct and plain question and desire a direct and plain answer. Don't tell me to just use the 'Button Tool', because it is nowhere to be found. 1. I created an adobe fillable form from scratch using AA9 Pro/LiveCycle. 2. I will d
-
Problem in Screen exit for MIGO using MB_MIGO_BADI?
hi all, I have customized the MIGO screen to add two fields and the data entered in these fields is saving in a custom data base table using the POST_DOCUMENT method of the BADI. The problem is i am unable to write the code to display these values in
-
Can't print contact sheet in iPhoto 11
iPhoto 11 9.4.3: OS 10.8.5; iMac mid 2011; Epson WP-4020 printer. All of a sudden, I cannot print a contact sheet from iPhoto. Had no problem doing so before. I now get error message from printer "Paper out, incorrect loading, or paper jam," none of
-
Hi Everybody, Hi i am working in manufacturing company giving support for SAP MM hence i am having functional knowledge as well as basic customization e.g release strategy , Number Ranges etc. In future i may join IT company , so please help for best