How to avoid Cartesian join in sqlquery
Please ignore this Thread.
Thanks
Lax
Edited by: LAX_ORA on 05-Nov-2012 08:23
It is always helpful to provide the following:
1. Oracle version (SELECT * FROM V$VERSION)
2. Sample data in the form of CREATE / INSERT statements.
3. Expected output
4. Explanation of expected output (A.K.A. "business logic")
5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
Similar Messages
-
Could anyone help me to avoid Cartesian join in this query?
Hi, guys:
Could you help me on this query? I must generate a Cartesian join, but I do not know why it happens. dt.debtorkey, cl.clientkey, inv.invoicekey, ag.agingkey are primary keys of each table. The problem is: I got same tuple for 8 times.
select dt.debtorkey, cl.clientkey, inv.invoicekey, ag.agingkey, dt.DebtorNo, dt.Name as "debtor Name", dt.State, cl.ClientNo, cl.Name as "Client Name", inv.InvNo, inv.PurchOrd, inv.Amt,
to_char(inv.InvDate, 'MM-DD-YY') invoice_date, to_char(ag.DateLastBuy, 'MM-DD-YY') aging_lastbuy, to_char(ag.DateLastPmt, 'MM-DD-YY') aging_lastpmt
from aging ag, invoices inv, debtors dt, clients cl
where ag.clientkey=cl.clientkey
and ag.debtorkey=dt.debtorkey
and inv.clientkey=cl.clientkey
and inv.debtorkey=dt.debtorkey
and ((inv.InvDate>=to_date(:P16_DP_IDF_START_DATE, 'MM/DD/YYYY')
and inv.InvDate<=to_date(:P16_DP_IDF_END_DATE, 'MM/DD/YYYY')
and ag.DateLastBuy=to_date(:P16_DP_IDF_LAST_BUY,'MM/DD/YYYY')
order by dt.name;Thanks a lot!Hi,
Thanks for help. I am sorry for that I do not know how to upload a picture of explain plan. I am struggling to find how to provide sample data. I hope this data format could be at least useful.
"DEBTORKEY","CLIENTKEY","INVOICEKEY","AGINGKEY","DEBTORNO","debtor Name","STATE","CLIENTNO","Client Name","INVNO","PURCHORD","AMT","INVOICE_DATE"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"I do not know why the tuples with same primary key repeat 8 times.
Edited by: lxiscas on Oct 24, 2012 4:08 PM
Edited by: lxiscas on Oct 24, 2012 4:10 PM -
[JPA] How to avoid excessive joins in queries on InheritanceType.JOINED
Hi,
Let me use an over-simplified example to illustrate my question:
Let's assume I have two classes: SuperClass and SubClass. As the name suggests, SubClass extends SuperClass.
I have mapped them in JPA via:
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="CTYPE", discriminatorType=DiscriminatorType.INTEGER)
@PrimaryKeyJoinColumn(name="ID")And now let's suppose I run the following query:
Query q = entityManager.createQuery("select o.id from SubClass o");In this case, TopLink Essentials generates SQL with a join between the base table and the detail table. Why? All I need is the ID which is available in the detail table too. The base table doesn't need to be included in the query.
Is there a way to avoid the unnecessary join? I even tried mapping the ID column in both entities but it didn't help.
Best regards,
BisserThank you for you reply, Doug!
I don't want to instantiate SubClass. I only wish to get the ID. I don't need validations or fields from the superclass.
Should I resort to using native SQL for that?
(By the way, the real query that I use in my program instantiates a completely different entity. I use the SubClass in a subquery. And I don't need the SuperClass to get involved. I have a foreign key that guarantees that the SuperClass's row exists in the database.)
Best regards,
Bisser -
How to avoid cartesion join is there any alternate way
Hi,
I have table
1.sitemaster
2.Invmaster
Sitemaster will have some hundrer sites and Invmaster will have thousands of items or product
I have an Situation for each site i need to show all product so iam linking with cartetion join but its taking more time
is there any other alternate way to get same result as cartetion join . Please can any one guide me?Hi iam saying i need a result like cartesion join only
Table invmaster
INVIID
SKU
UPC
DESCRIPTION
DATEADDED
MAINGROUP
AVAILGROUP
REPORTGROUP
COMMGROUP
TAXGROUP
EXCHANGEGROUP
ATTRGROUP
METERGROUP
MANUFACTURER
MANPARTNUM
MODEL
ACTIVE
MADEIN
QTYSERIAL
SELLPRICE
COST
LOWESTSELLPRICE
REPLACEMENTCOST
ALLOWDISCOUT
DAMAGEWAIVER
ALLOWSUBRENT
ALLOWCONSIGNED
SHELFLOCATION
BINNUMBER
PACKAGE
TYPE
DEPOSITTYPE
DEPOSITVALUE
AFFECTSAVAILABILITY
URL
UCDESCRIPTION
PRINTONORDER
ISMISCITEM
LENGTH
WIDTH
HEIGHT
WEIGHT
BOOKDEPRECIATIONIID
TAXDEPRECIATIONIID );
Sitemaster
SITEIID
SITEID
SITENAME
ADDRESSIID
GMT
PARENTIID
PARENTSERVER
REGION
DISTRICT
CLASS
SITEPRICEGROUP
PHONE
FAX
DAYSINWEEK
TIMEZONE
SHIPDATEOFFSET
PHYSICALCOUNTSTART
LOCALE
GEOGRAPHICALREGION
CATEGORYGROUPIID
RETURNDATEOFFSET
MASTERBILLSHARINGTYPE
MASTERBILLSHARING
SERVICECHARGETYPE
SERVICECHARGEVALUE
SCONDISCOUNTEDAMOUNT
SERVICECHARGEONSELLITEMS );
I have created view such that linking othere table with columns index,
but only in sitemaster i made cartetion join but my result is as expected but its taking more time below is my
plan please can you suggest is there any alternate way?
Execution Plan
Plan hash value: 4005734062
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 2 | 11822 | 24 (9)| 00:00:01 |
| 1 | VIEW | ALLITEMVIEW | 2 | 11822 | 24 (9)| 00:00:01 |
| 2 | UNION-ALL | | | | | |
| 3 | NESTED LOOPS OUTER | | 1 | 164 | 2 (0)| 00:00:01 |
|* 4 | TABLE ACCESS BY INDEX ROWID | INVMASTER | 1 | 149 | 2 (0)| 00:00:01 |
|* 5 | INDEX UNIQUE SCAN | IDX_INVMASTERSKU | 1 | | 1 (0)| 00:00:01 |
| 6 | TABLE ACCESS BY INDEX ROWID | INVSUBCATEGORY | 2 | 30 | 0 (0)| 00:00:01 |
|* 7 | INDEX UNIQUE SCAN | PK_INVSUBCATEGORYIID | 1 | | 0 (0)| 00:00:01 |
|* 8 | HASH JOIN OUTER | | 1 | 1886 | 22 (10)| 00:00:01 |
| 9 | NESTED LOOPS OUTER | | 1 | 1873 | 19 (0)| 00:00:01 |
| 10 | NESTED LOOPS OUTER | | 1 | 818 | 17 (0)| 00:00:01 |
| 11 | VIEW | SITEITEMVIEW | 1 | 676 | 17 (0)| 00:00:01 |
|* 12 | FILTER | | | | | |
| 13 | NESTED LOOPS | | 11 | 2827 | 17 (0)| 00:00:01 |
| 14 | NESTED LOOPS OUTER | | 1 | 226 | 2 (0)| 00:00:01 |
|* 15 | TABLE ACCESS BY INDEX ROWID| INVMASTER | 1 | 214 | 2 (0)| 00:00:01 |
|* 16 | INDEX UNIQUE SCAN | IDX_INVMASTERSKU | 1 | | 1 (0)| 00:00:01 |
| 17 | TABLE ACCESS BY INDEX ROWID| INVSUBCATEGORY | 2 | 24 | 0 (0)| 00:00:01 |
|* 18 | INDEX UNIQUE SCAN | PK_INVSUBCATEGORYIID | 1 | | 0 (0)| 00:00:01 |
| 19 | TABLE ACCESS FULL | SITEMASTER | 11 | 341 | 15 (0)| 00:00:01 |
|* 20 | INDEX RANGE SCAN | IDX_COMSITEAUTHORIZEDPRODUCTS | 1 | 13 | 0 (0)| 00:00:01 |
|* 21 | INDEX UNIQUE SCAN | IDX_COMSITEAUTHORIZEDPRODUCTS | 1 | 26 | 0 (0)| 00:00:01 |
| 22 | TABLE ACCESS BY INDEX ROWID | IMAGEFILEREFERENCE | 1 | 142 | 0 (0)| 00:00:01 |
|* 23 | INDEX RANGE SCAN | IDX_IMAGEFRPARENTIID | 1 | | 0 (0)| 00:00:01 |
| 24 | VIEW PUSHED PREDICATE | INVITEMVIEW | 1 | 1055 | 2 (0)| 00:00:01 |
| 25 | NESTED LOOPS | | 1 | 45 | 2 (0)| 00:00:01 |
| 26 | NESTED LOOPS | | 1 | 30 | 1 (0)| 00:00:01 |
|* 27 | INDEX UNIQUE SCAN | PK_SITEMASTER | 1 | 10 | 0 (0)| 00:00:01 |
| 28 | TABLE ACCESS BY INDEX ROWID | INVNONSERIAL | 1 | 20 | 1 (0)| 00:00:01 |
|* 29 | INDEX UNIQUE SCAN | IDX_INVNONSERIALSITEIIDINVIID | 1 | | 0 (0)| 00:00:01 |
|* 30 | TABLE ACCESS BY INDEX ROWID | INVMASTER | 1 | 15 | 1 (0)| 00:00:01 |
|* 31 | INDEX UNIQUE SCAN | PK_INVMASTER | 1 | | 0 (0)| 00:00:01 |
| 32 | VIEW | | 6 | 78 | 2 (50)| 00:00:01 |
| 33 | HASH UNIQUE | | 6 | 30 | 2 (50)| 00:00:01 |
| 34 | INDEX FULL SCAN | PK_SUGGESTEDITEMS | 21 | 105 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------------------- -
Hi
Assume I have following table
Id Code
1 aa
1 bb
1 cc
2 bb
2 cc
The records will be grouped by Id. I want to find out group containing code say 'aa' and 'bb'.
Is it possible to obtain the desired result in a single query without using Self join?
Regards
~PravinThis is a little clumsy....Anyway try it:
WITH t AS
(SELECT 1 id,'aa' code FROM dual
UNION ALL
SELECT 1,'bb' FROM dual
UNION ALL
SELECT 1,'cc' FROM dual
UNION ALL
SELECT 2,'bb' FROM dual
UNION ALL
SELECT 2,'cc' FROM dual)
SELECT id FROM t
WHERE code IN('aa', 'bb')
GROUP BY id HAVING COUNT(*) = 2; -
How to join 2 tables with unequal rows without resulting in a cartesian join
Hello,
This is the first time I have ever posted in any forum so please tell me if I should be doing this better.
Basically I have 2 tables with an unequal number of rows. For demonstration purposes, assume these are my 2 tables:
Table 1:
BaseKey
Letters
A
A
A
B
A
C
B
A
B
B
Table 2:
BaseKey
Numbers
A
1
A
2
B
1
B
2
B
3
I need to join them so that the data would appear like this
BaseKey
Letters
Numbers
A
A
1
A
B
2
A
C
null
B
A
1
B
B
2
B
null
3
Does anyone have any ideas how to do this using T-SQL without creating a cartesian join of 12 rows?
Thanks.>> This is the first time I have ever posted in any forum so please tell me if I should be doing this better. <<
Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums. What you did post is useless! Can you program from it? Neither can we. And we have to do all the extra typing for you.
CREATE TABLE Foo
(base_something CHAR(1) NOT NULL,
something_letter CHAR(1) NOT NULL,
PRIMARY KEY (base_something, something_letter));
INSERT INTO Foo
VALUES ('A', 'A'),
('A', 'B'),
('A', 'C'),
('B', 'A'),
('B', 'B');
CREATE TABLE Bar
(CHAR(1) NOT NULL,
something_digit CHAR(1) NOT NULL,
PRIMARY KEY (base_something, something_digit));
INSERT INTO Foo
VALUES ('A', '1'),
('A', '2'),
('B', '1'),
('B', '2'),
('B', '3');
>> I need to join them so that the data would appear like this
base_something Letters Numbers <<
This looks like you are taking two decks of punch cards and merging them together, without any logical rules, just physical position in their decks relative to the base_something groups.
WITH Foo_Deck
AS
(SELECT base_something, something_letter,
ROW_NUMBER()
OVER (PARTITION BY base_something
ORDER BY something_letter) AS card),
Bar_Deck
AS
(SELECT base_something, something_digit,
ROW_NUMBER()
OVER (PARTITION BY base_something
ORDER BY something_digit) AS card),
SELECT F.base_something, F.something_digit, B.something_letter
FROM Foo_Deck AS F
LEFT OUTER JOIN
Bar_Deck AS B
ON B.base_something = F.base_something
AND B.card = F.card;
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
How to avoid duplicates in CROSS JOIN Query
Hi,
I am using CROSS JOIN to get all the subset of a table col values as shown below:
PRODUCT (Col Header)
Bag
Plate
Biscuit
While doing cross join we will get as
Bag Bag
Bag Plate
Bag Biscuit
Plate Bag
Plate Plate
Plate Biscuit ..... like this
By placing where condition prod1 <> prod2 to avoid Bag Bag and Plate Plate values. So the output will be like below
Bag Plate
Bag Biscuit
Plate Bag
Plate Biscuit
Now "Bag Plate" and "Plage Bag" are same combination how to avoid these records. My expected result is
Bag Biscuit
Plate Biscuit
How to derive this ?
SridharHi,
This is the the solution that I found as fit to the OP question, but
Visakh16 already posted the same idea (assuming the names are unique) from the start and I don't think that anyone notice it!
Sridhar.DPM did
you check Visakh16's response
(the second response received)?!?
I will mark his response as an answer. If this is not what you need pls clarify and you can unmark it :-)
[Personal Site] [Blog] [Facebook] -
How to avoid Duplicate Records while joining two tables
Hi,
I am trying to join three tables, basically two tables are same one is like history table, so I wrote a query like
select
e.id,
e.seqNo,
e.name,
d.resDate,
d.details
from employees e,
((select * from dept)union(select * from dept_hist)) d
join on d.id=e.id and e.seqno=d.seqno
but this returing duplicate records.
Could anyone please tell me how to avoid duplicate records of this query.Actually it is like if the record is processed it will be moved to hist table, so both table will not have same records and I need the record from both the tables so i have done the union of both the tables, so d will have the union of both records.
But I am getting duplicate records if even I am distinct. -
CacheSplitMemoryReader - Cartesian join?
Hi,
We have a process where we run multiple matches on the input file, and then group number from each match is sent to a query transform to do an outer join before it is sent to associative match transform.
The process runs fine with small data set, but when we ran it for a production size file, the process ran for about 15 hours.
Looking at the monitor logs, we see a very large number against "CacheSplitMemoryReader".
While testing it with small set (say, 11 records in the input file), I see "121" rowcount against "CacheSplitMemoryReader".
Though I am not sure what "CacheSplitMemoryReader" means, my guess is that it is related to the join. And for some reason, while joining all the four input streams, DS decides to do a Cartesian join?
Though, the output is fine - with 11 records coming out of associative match.
We have tried changing outer join order in the query transform to see if that makes any difference. But so far, everytime it ends up with 121 records for "CacheSplitMemoryReader".
Any insight into what is happening and how to avoid it?
Thanks,
Gaurav
Edit: This is for DataService 12.2.0.1
Edited by: Gaurav Pandit on Nov 4, 2009 2:53 PMHello Gaurav,
I am curious why you are doing this join at all.
If you are trying to optimize the peformance of Associate, I recommend bypassing the rows that have no group number. In other words Associate should receive only the rows that have at least one group number populated. And then you will have to Merge back the rows.
I also recommend referring our bluprints posted here SAP Data Services Blueprints for example usage of Match and Associate. Please take a look at jobs named *_MatchAssociative. Here you will see how specific rows are bypassed and merged back for different Match transform. Similar principle can be applied for Associate. The Case condition will be based on Group Numbers.
Thanks,
Abhiram -
How to avoid the message in the dashboard report
Hi,
I am developing Dashboard reports(graphs) using WAD. Query and WAD are working fine. I need to put a variable for Calendar Month or Year in the graph .I am populating the Variable with default value initially and I am getting the correct result . But if I change the Variable value second time, I am getting a message (type I(information) ) in the same screen which says that 'You cannot change variable ZCALYEAR_WT01 for charact. 0CALYEAR during query navigation' . And below is the detailed information about the error message.
The Can be changed in query navigation property has been set for variable ZCALYEAR_WT01, characteristic 0CALYEAR. However, the variable is used in the query in such a way, that the system is unable to apply this change-option.
This can, for example, occur under the following conditions:
Characteristic 0CALYEAR is filtered by additional restrictions (the restrictions must be joined using an OR-connection)
A second characteristic, which is restricted by a variable, is compounded to charcteristic 0CALYEAR.
Variable ZCALYEAR_WT01 is a hierarchy node variable, but the hierarchy has not been determined uniquely.
A variable can be changed during query navigation only if it is used exclusively in a drilldown-characteristic, and there are no further restrictions to the characteristic other than this variable. There must be no additional characteristics with variables compounded to the characteristic you are working with. For variables for hierarchy nodes, the hierarchy must be determined uniquely and agree with the set display hierarchy.
Also, if the characteristic value is moved, for example (ZCALYEAR_WT01 - 1), the variable is no longer able to be changed when navigating queries.
System Response
The entry ZCALYEAR_WT01 Can be changed during query navigation is not applied.
Procedure
I checked the query definition and it is not having any offset or any other restrictions for Calendar Year
It is used for finding the total quantity by country for the year .Hence Quantity keyfigure is added in the Keyfigures and Country is in the Rows and Calendar Year is restricted with Variable in the global filter .There are no other fields and no other restrictions .
I am still trying to figure out why the warning apprears in the DashBoard. Since this Dashboard report will be used by the Power users and this warning message will be annoying to them .Hence I need to find how to avoid this message.
Kindly do let me if anyone has faced this and solved earlier.
Thanks for your time.
Thanks & Regards,
RajaHi Nick,
Thanks for your suggestion and it worked for me I added the 'System message' web item and set the visibility to 'Hidden' .Now I am not getting any message. Thank you for both.
Thanks & Regards,
Raja -
How to avoid Flickaring When Adding data in Addon User Matrix
Experts,
I am Adding Query Result in User Matrix one by one. but there is lots of Flicker.
how to Avoid this Flickering.
Bomiitems = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
If Bomtyp = "U" And BomNo = "0" Then
BOMItem = "SELECT Distinct T0.[Code], T1.[ItemName] , ( 1 / Isnull(T2.[Qauntity],0))* Isnull((T0.[Quantity]),0),('" & Quanti & "'/ Isnull(T2.[Qauntity],0))* Isnull((T0.[Quantity]),0) as "
BOMItem = BOMItem + " 'Quanti',T1.[Excisable],'N' as U_Rec , T1.[InvntryUom],T0.[Warehouse] 'Warehouse',T0.[IssueMthd]'IssMthd' FROM ITT1 T0 INNER JOIN OITM T1 "
BOMItem = BOMItem + " ON T0.Code = T1.ItemCode INNER JOIN OITT T2 ON T0.Father = T2.Code "
BOMItem = BOMItem + " WHERE T0.[Father] ='" & Icode & "'"
Bomiitems.DoQuery(BOMItem)
ElseIf Bomtyp = "U" And BomNo <> "0" Then
'BOMItem = "SELECT T0.[Code], T1.[ItemName] , ((T0.[Quantity]/ T2.[Qauntity])*'" & Quanti & "') as 'Quanti',T1.[Excisable],'N' as U_Rec FROM ITT1 T0 INNER JOIN OITM T1 ON T0.Code = T1.ItemCode INNER JOIN OITT T2 ON T0.Father = T2.Code WHERE T0.[Father] ='" & Icode & "'"
BOMItem = "SELECT T1.[U_Icode], T1.[U_IName],(1 / Isnull(Cast( T0.[U_Bqty] as Float) ,0)) * Isnull(Cast(T1.[U_Quanti] As Float),0) ,('" & Quanti & "' / Isnull(Cast( T0.[U_Bqty] as Float) ,0)) * Isnull(Cast(T1.[U_Quanti] As Float),0) as 'Quanti',T2.[Excisable], T0.[U_Rec],T2.[InvntryUom] ,T1.[U_Whs] 'Warehouse','B' AS 'IssMthd' "
BOMItem = BOMItem + "FROM [dbo].[@OITTA] T0 inner join [dbo].[@ITTA1] "
BOMItem = BOMItem + "T1 on t0.cODE = t1.Code INNER JOIN OITM T2 ON T1.[U_Icode] = T2.[ItemCode]"
BOMItem = BOMItem + " WHERE T0.[U_Icode] = '" & Icode & "' AND T0.[U_AltBom] ='" & BomNo & "' AND T0.U_Btyp = 'U' "
Bomiitems.DoQuery(BOMItem)
ElseIf Bomtyp = "P" Then
BOMItem = "SELECT T1.[U_Icode], T1.[U_IName],(1 / Isnull(Cast( T0.[U_Bqty] as Float) ,0)) * Isnull(Cast(T1.[U_Quanti] As Float),0),('" & Quanti & "' / Isnull(Cast( T0.[U_Bqty] as Float) ,0)) * Isnull(Cast(T1.[U_Quanti] As Float),0) as 'Quanti',T2.[Excisable], T0.[U_Rec] ,T2.[InvntryUom],T1.[U_Whs] 'Warehouse','B' AS 'IssMthd' "
BOMItem = BOMItem + "FROM [dbo].[@OITTA] T0 inner join [dbo].[@ITTA1] "
BOMItem = BOMItem + "T1 on t0.cODE = t1.Code INNER JOIN OITM T2 ON T1.[U_Icode] = T2.[ItemCode]"
BOMItem = BOMItem + " WHERE T0.[U_Icode] = '" & Icode & "' AND T0.[U_AltBom] ='" & BomNo & "' AND T0.U_Btyp = 'P' "
Bomiitems.DoQuery(BOMItem)
End If
Bomiitems.DoQuery(BOMItem)
If Bomiitems.RecordCount > 0 Then
'RecCount1 = RecSet1.RecordCount
Bomiitems.MoveFirst()
i = 0
'osubForm .Freeze(True)
oMatrix = oForm.Items.Item("1000001").Specific
oMatrix.FlushToDataSource()
While Not (Bomiitems.EoF)
If i = 0 Then
oMatrix.AddRow()
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("LineId", 0, i + 1)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_ItemCode", 0, Bomiitems.Fields.Item(0).Value)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_ItemName", 0, Bomiitems.Fields.Item(1).Value)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_BaseQty", 0, Bomiitems.Fields.Item(2).Value)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_PlanQty", 0, Bomiitems.Fields.Item(3).Value)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_IssueQty", 0, Bomiitems.Fields.Item(3).Value)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_Whs", 0, Bomiitems.Fields.Item("Warehouse").Value)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_IsueType", 0, Bomiitems.Fields.Item("IssMthd").Value)
Dim orsWhsDetails As SAPbobsCOM.Recordset
Dim strWhsDetails As String
orsWhsDetails = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
strWhsDetails = "SELECT T0.[OnHand], T0.[IsCommited], T0.[OnOrder],T1.[OnHand] FROM OITW T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode WHERE T0.[ItemCode] ='" & Bomiitems.Fields.Item(0).Value & "' AND T0.[WhsCode] ='" & Bomiitems.Fields.Item("Warehouse").Value & "' "
orsWhsDetails.DoQuery(strWhsDetails)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_Whsestk", 0, orsWhsDetails.Fields.Item(0).Value)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_AVILSTK", 0, (orsWhsDetails.Fields.Item(0).Value - Bomiitems.Fields.Item(3).Value))
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_PLANTSTK", 0, orsWhsDetails.Fields.Item(3).Value)
oMatrix.LoadFromDataSource()
Else
oMatrix.FlushToDataSource()
oForm.DataSources.DBDataSources.Item("@TPROD1").InsertRecord(i)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("LineId", i, i + 1)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_ItemCode", i, Bomiitems.Fields.Item(0).Value)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_ItemName", i, Bomiitems.Fields.Item(1).Value)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_BaseQty", i, Bomiitems.Fields.Item(2).Value)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_PlanQty", i, Bomiitems.Fields.Item(3).Value)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_IssueQty", i, Bomiitems.Fields.Item(3).Value)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_Whs", i, Bomiitems.Fields.Item("Warehouse").Value)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_IsueType", i, Bomiitems.Fields.Item("IssMthd").Value)
Dim orsWhsDetails As SAPbobsCOM.Recordset
Dim strWhsDetails As String
orsWhsDetails = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
strWhsDetails = "SELECT T0.[OnHand], T0.[IsCommited], T0.[OnOrder],T1.[OnHand] FROM OITW T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode WHERE T0.[ItemCode] ='" & Bomiitems.Fields.Item(0).Value & "' AND T0.[WhsCode] ='" & Bomiitems.Fields.Item("Warehouse").Value & "' "
orsWhsDetails.DoQuery(strWhsDetails)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_Whsestk", i, orsWhsDetails.Fields.Item(0).Value)
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_AVILSTK", i, (orsWhsDetails.Fields.Item(0).Value - Bomiitems.Fields.Item(3).Value))
oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_PLANTSTK", i, orsWhsDetails.Fields.Item(3).Value)
oMatrix.LoadFromDataSource()
End If
i = i + 1
Bomiitems.MoveNext()
oMatrix.LoadFromDataSource()
End While
oMatrix.LoadFromDataSource()
End If
Regards,
Pravin Bajifollow steps
1) Execute query so we can get data set
2) Clear matrix and data source (omatrix.clear(), oDBS.Clear())
3) Open loop
4) Insert record to oDBS using oDBS.InsertRecords(oDBS.Offset)
5) Then set value using oDBS.Setvalue(u2026u2026
6) Move next record
7) Finally close the loop
8) Matrix load from record set using oMatrix.LoadfromData()
it will be work -
How to Avoid wrong spell MD values at Qry selection
Hi all,
The issue is at Query Selection:
We set:
Query def. Filter value selection = Only values in infoprovider
Query Execution Filter Val. Selectn = Only values in InfoProvider
I want to see only Info provider(TD) values not Master values @ Qry selection for the info object (customer)
Example
Customer MD:
CID:
John - correct name
JOKN - Wrong spell
We Don't want to delete these values.
- NO records there in cube for (CID = JOKN) and in reports with the name JOKN
I want to see only JOHN in selection not JOKN(Wrong spell).
Please tell me how to avoid wrong spell values at Qry selection level without deleting Master data.
Thanks in advanceHello Nara,
One solution is to write customer-exit variable that will be populated only by correct values. You can archieve this by joining master data table with DSO active table
or master data table with dimension table and fact table(s).
Now restrict query with this non-input variable in restrictions and create input variable that will take place in default values.
But since it's customer master data you may encounter serious performance problems. I guess that's the reason why BEx doesn't do this by default.
BR
Ondrej -
How to avoid select with in a loop.
Hi friends,
can any tell how to avoid the select with in a loop for the following code, since it badly effecting my performance. if possible with code
SELECT matnr werks
FROM marc
INTO TABLE it_marc
FOR ALL ENTRIES IN it_ausp_1
WHERE matnr = it_ausp_1-objek AND
werks = p_werks
AND mmsta LE 60.
SORT it_marc BY matnr.
CLEAR wa_ausp_1.
CLEAR wa_tabix.
LOOP AT it_ausp_1 INTO wa_ausp_1.
wa_tabix = sy-tabix.
READ TABLE it_marc INTO wa_marc WITH
KEY matnr = wa_ausp_1-objek
BINARY SEARCH.
IF sy-subrc EQ 0.
ELSE.
DELETE it_ausp_1 INDEX wa_tabix.
ENDIF.
ENDLOOP. " LOOP AT it_ausp_1 INTO wa_ausp_1.
APPEND LINES OF it_ausp_1 TO it_tal.
IF it_tal[] IS NOT INITIAL.
LOOP AT t_plan_order INTO fs_plan_order.
SELECT r~rsnum
r~rspos
r~matnr
r~nomng
r~meins
r~plnum
r~bdter
r~ewahr
r~alprf
r~posnr
r~baugr
m~dispo
INTO TABLE t_resb
FROM resb AS r
INNER JOIN marc AS m
ON rbaugr = mmatnr
AND rwerks = mwerks
FOR ALL ENTRIES IN it_tal
WHERE r~rsnum = fs_plan_order-rsnum
AND r~matnr = it_tal-objek
AND r~xloek = ' '
AND r~werks = p_werks.
APPEND LINES OF t_resb TO t_tacl.
ENDLOOP.SELECT r~rsnum r~rspos r~matnr r~nomng r~meins r~plnum r~bdter r~ewahr r~alprf r~posnr r~baugr m~dispo
INTO TABLE t_resb
FROM resb AS r
INNER JOIN marc AS m
ON r~baugr = m~matnr
AND r~werks = m~werks
FOR ALL ENTRIES IN it_tal
WHERE r~rsnum = fs_plan_order-rsnum
AND r~matnr = it_tal-objek
AND r~xloek = ' '
AND r~werks = p_werks.
The logic of this select is completely weird. Whcih order of the db-tables should be used, which indexes?
On RESB matnr, werks and xloek are in one index, but rsnum not.
Are the conditions in fs_plan_order and it_tal connected or independent?
It is probably much faster, to leave the fs_plan_order condition away and check it on the result.
SELECT r~rsnum r~rspos r~matnr r~nomng r~meins r~plnum r~bdter r~ewahr r~alprf r~posnr r~baugr m~dispo
INTO TABLE t_resb
FROM resb AS r
INNER JOIN marc AS m
ON m~matnr = r~baugr
AND m~werks = r~werks
FOR ALL ENTRIES IN it_tal
WHERE AND r~matnr = it_tal-objek
AND r~xloek = ' '
AND r~werks = p_werks.
sort fs_plan_order by rsnum.
loop at it_tal in wa.
read table fs_plan_order
with key rsnum = wa-rsnum
binary search.
if sy-subrc eq 0.
append ...
endif.
endloop.
Siegfried -
Cartesian Join of xmltables.
Hi,
SQL> var xml varchar2(3999)
SQL> begin
2 :xml := '<X12 NAME="856.edi">
3 <ISA01>00</ISA01>
4 <ISA02>XXXXXXXXXX</ISA02>
5 <ISA03>00</ISA03>
6 <ISA04>XXXXXXXXXX</ISA04>
7 <ISA05>ZZ</ISA05>
8 <ISA ID="552101">
9 <GS01>SH</GS01>
10 <GS02>xxxxxxxx</GS02>
11 <GS03>xxxxxxxxx</GS03>
12 <GS04>20060815</GS04>
13 <GS05>015219</GS05>
14 <GS06>xxxxxxxxxx</GS06>
15 <GS07>X</GS07>
16 <GS08>004010</GS08>
17 <GS ID="552102">
18 <ST01>856</ST01>
19 <ST02>0001</ST02>
20 <ST ID="552103">
21 <LIN>
22 <LIN02>IN</LIN02>
23 <LIN03>9D00025443</LIN03>
24 <LIN04>PO</LIN04>
25 <LIN05>25254404</LIN05>
26 </LIN>
27 <SN1>
28 <SN102>552</SN102>
29 <SN103>EA</SN103>
30 </SN1>
31 <LIN>
32 <LIN02>IN</LIN02>
33 <LIN03>9D00025443</LIN03>
34 <LIN04>PO</LIN04>
35 <LIN05>25255149</LIN05>
36 </LIN>
37 <SN1>
38 <SN102>1104</SN102>
39 <SN103>EA</SN103>
40 </SN1>
41 <CTT>
42 <CTT01>9</CTT01>
43 </CTT>
44 <SE>
45 <SE01>38</SE01>
46 <SE02>0001</SE02>
47 </SE>
48 </ST>
49 </GS>
50 <GE>
51 <GE01>1</GE01>
52 <GE02>913823084</GE02>
53 </GE>
54 <IEA>
55 <IEA01>1</IEA01>
56 <IEA02>913823084</IEA02>
57 </IEA>
58 </ISA>
59 </X12>';
60 end;
61 /
PL/SQL procedure successfully completed.
SQL> set long 32000
SQL> SELECT VALUE (i).EXTRACT ('/*')
2 FROM
3 TABLE (XMLSEQUENCE (EXTRACT (XMLTYPE (:xml), '/X12/ISA/GS/ST'))) k,
4 TABLE (XMLSEQUENCE (EXTRACT (VALUE (k), '/ST/LIN'))) i;
VALUE(I).EXTRACT('/*')
<LIN>
<LIN02>IN</LIN02>
<LIN03>9D00025443</LIN03>
<LIN04>PO</LIN04>
<LIN05>25254404</LIN05>
</LIN>
<LIN>
<LIN02>IN</LIN02>
<LIN03>9D00025443</LIN03>
<LIN04>PO</LIN04>
<LIN05>25255149</LIN05>
</LIN>
SQL>
SQL> SELECT VALUE (i).EXTRACT ('/*')
2 FROM
3 TABLE (XMLSEQUENCE (EXTRACT (XMLTYPE (:xml), '/X12/ISA/GS/ST'))) k,
4 TABLE (XMLSEQUENCE (EXTRACT (VALUE (k), '/ST/LIN'))) i,
5 TABLE (XMLSEQUENCE (EXTRACT (VALUE (k), '/ST/SN1'))) m;
VALUE(I).EXTRACT('/*')
<LIN>
<LIN02>IN</LIN02>
<LIN03>9D00025443</LIN03>
<LIN04>PO</LIN04>
<LIN05>25254404</LIN05>
</LIN>
<LIN>
<LIN02>IN</LIN02>
<LIN03>9D00025443</LIN03>
<LIN04>PO</LIN04>
<LIN05>25254404</LIN05>
</LIN>
<LIN>
<LIN02>IN</LIN02>
<LIN03>9D00025443</LIN03>
<LIN04>PO</LIN04>
<LIN05>25255149</LIN05>
</LIN>
<LIN>
<LIN02>IN</LIN02>
<LIN03>9D00025443</LIN03>
<LIN04>PO</LIN04>
<LIN05>25255149</LIN05>
</LIN>I am trying to put the LIN and SN1 segment into one row. But, when I do it this way, it is giving me cartesian join. I tried doing this using XMLTable operator too. I couldn't get anywhere.Look at the example of the manual (XMLDB Developers Guide) regarding the use of XMLQuery and XMLTable: Example 17-12 Using XMLTable to Shred XML Collection Elements into Relational Data
or given the following example, can you work it out now for your situation?
SQL*Plus: Release 10.2.0.2.0 - Production on Tue Oct 10 20:52:53 2006
Copyright (c) 1982, 2005, Oracle. All Rights Reserved.
SQL> @login
SQL> conn oe/[email protected]
Connected.
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
5 rows selected.
SQL> CREATE OR REPLACE VIEW purchaseorder_detail_view AS
2 SELECT po.reference, li.*
3 FROM purchaseorder p,
4 XMLTable('/PurchaseOrder' PASSING p.OBJECT_VALUE
5 COLUMNS
6 reference VARCHAR2(30) PATH 'Reference',
7 lineitem XMLType PATH 'LineItems/LineItem') po,
8 XMLTable('LineItem' PASSING po.lineitem
9 COLUMNS
10 itemno NUMBER(38) PATH '@ItemNumber',
11 description VARCHAR2(256) PATH 'Description',
12 partno VARCHAR2(14) PATH 'Part/@Id',
13 quantity NUMBER(12, 2) PATH 'Part/@Quantity',
14 unitprice NUMBER(8, 4) PATH 'Part/@UnitPrice') li;
View created.
SQL> desc purchaseorder_detail_view
Name Null? Type
REFERENCE VARCHAR2(30)
ITEMNO NUMBER(38)
DESCRIPTION VARCHAR2(256)
PARTNO VARCHAR2(14)
QUANTITY NUMBER(12,2)
UNITPRICE NUMBER(8,4)
SQL> select * from purchaseorder_detail_view
1 where rownum <= 10;
REFERENCE ITEMNO DESCRIPTION PARTNO QUANTITY UNITPRICE
CJOHNSON-20021009123337283PDT 1 Rushmore 715515010429 1 39.95
CJOHNSON-20021009123337283PDT 2 The Magic Flute 37429147528 2 29.95
CJOHNSON-20021009123337283PDT 3 How to Get Ahead in Advertising 715515012324 1 29.95
CJOHNSON-20021009123337283PDT 4 Written on the Wind 715515011525 3 29.95
CJOHNSON-20021009123337283PDT 5 Spartacus 715515011723 2 39.96
CJOHNSON-20021009123337283PDT 6 The Hidden Fortress 37429135129 2 29.95
CJOHNSON-20021009123337283PDT 7 Amarcord 37429121825 1 39.95
CJOHNSON-20021009123337283PDT 8 The Harder They Come 715515010825 3 39.95
CJOHNSON-20021009123337283PDT 9 George Washington 37429166123 2 39.95
CJOHNSON-20021009123337283PDT 10 Sanjuro 37429141526 1 29.95
10 rows selected.
Message was edited by:
mgralike -
Cartesian Join query optimization
Hello Experts!
I have a question about cartesian join query which might look a bit weird.
Assume the SQL query like that:
SELECT DISTINCT A.NAME
FROM A, B, C;
Here we have cartesian join for 3 tables A, B and C.
It looks to me, in order to get the result for such a particular SQL tables/sets B and C need to be accessed only to ensure they return at least 1 row (otherwise result set is empty), query table A, but there is no actual need to join the data.
If you run such a query Oracle is doing full table scans and actually joins the data.
Yes, DBMS is doing exactly what you are asking for, but I wonder if there is any way (SQL hint or db parameter or anything else) to enforce more optimal access path here?
Obvious solution to remove B and C tables from the SELECT statement is not acceptable. :-)
Thank you!Your statement in the other thread indicates you don't understand how the BI prompts actually work because you say you want it to do something that doesn't make sense for it to do.
Of course Product and Account levels will be constrained to the interval you specified. It wouldn't make sense for them not to be. Because that would mean returning data for based on product and account levels that has a different open data range than what you specified.
All UI prompt dialogs I have seen use AND relationships between the parameters. If there are three parameters (A, B, C) then the ultimate relationship is 'A AND B AND C'; not 'A OR (B AND C)', 'A AND (B OR C)', 'A OR (B OR C).
Unless the tool allows you to select OR relationships you need to use a separate dialog box (parameter dialog) for each condition set.:-)
I understand how BI prompts work and basically agree on your comment, but there are two problems here:
1. I need to convince the customer his original requirements are not valid. Customer want it to work different way and there are some reasons why.
2. There are pretty large dimensions and fact tables used here, so when I choose filter criteria for the Product (which is small table) to populate/recalculate prompt values, large SR dimension and fact tables are joined too, and if there are Account dimension filters added, huge Account dimension will be added as well. This looks to be a bit sub-optimal for just populating the Product prompt values.
Of course, technically this is solvable, but requires to put some extra effort and does not solve the 1st issue.
That other link doesn't explain the sample code you posted in this thread. Post the actual query that is being generated and the query that you want to actually use.This is what is generated:
>
select distinct T311691.X_CUST_SUBTYPE as c1
from
WC_LOV_SR_AREA_H T311695,
WC_LOV_PROD_H T311687,
WC_LOV_CUST_TYPE_H T311691,
W_SRVREQ_D T302384 /* Dim_W_SRVREQ_D */
where ( T311687.LEV1 = 'Product X' and T311691.X_CUST_TYPE = 'Business' and T302384.OPEN_DT between TO_DATE('2012-03-01 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') and TO_DATE('2012-03-31 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') )
order by c1
>
This is what is actually needed to query this data:
>
select distinct T311691.X_CUST_SUBTYPE as c1
from
WC_LOV_CUST_TYPE_H T311691
where ( T311691.X_CUST_TYPE = 'Business' )
order by c1
Maybe you are looking for
-
Hi All.. Presently I m working in TCS(2007 Passout). recently I hav undergone ABAP training conducted in TCS by SAP Education Services,and now waitiing for related projects here..But as told by HR currently no requirements for ABAPers..and also they
-
How to monitor Message Bridge runtime using WLST
Hi Readers, I would like to monitor Message Bridge runtime on weblogic 8.1 using WLST script. Can anybody tell if there is any possibility? Is there a MBEAN avaialble for Messaging Bridge.? Edited by: user13254842 on 09-Sep-2010 23:17
-
Has anyone done Export/Import from Oracle 8i (8.1.5) to Oracle Ver 8.0.6. I went through the documentation. It says I have to use Export Utility Release 8.0 against Oracle 8i database. But this utility is not comes along with Oracle 8i. Does this mea
-
Advantages and disadvantages of APEX?
Hey Guys, what would you say are the advantages and disadvantages of APEX? I am interested in the opinion of you as developer! (I know that there are a lot of information given by Oracle......) I would be very glad if you can post some short advantag
-
A while ago I noticed these entries in the Hub Event Log. At the time there were no active PC's powered on. What does the entry "[CWMP] Connection Request NOT ALLOWED." indicate? It appears that a warm reset was trigered. Who was Lua user in "SYSTEM