Order Query in SQ01 using Table Joins in CRM
Hello Experts,
I am trying to create a query using table joins in SQ01 in CRM because I need a report that will give me all transactions for a selected Business Partner. I am unable to display any results when running my query. I have found other threads which give a list of possible tables to join together, but the fields used in the joins were not described.
The tables I have joined in my query are as follows:
CRMD_ORDERADM_H
CRMD_ORDER_INDEX
CRMD_PARTNER
BUT_000
I have used SE16 to try to search for additional tables to use for linking the Business Partner with a transaction, but I have been unsuccessful.
Would anyone please give advice as how to proceed?
Reward points are available!
Thank you in advance,
David
David
The link with be the GUID.
CRMD_ORDERADM_H = Document Header Table
CRMD_ORDERADM_I = Document Line item Table
CRMD_LINK = Lists various link GUIDs, to
access order Information
The Table CRMD_ORDERADM_H will contain you transactions , once you find the GUID of your sales transaction in the table CRMD_ORDERADM_H.
You then need to check the table CRMD_LINK.
In this table you will then find a number in 11 = sales. This refers to the table CRMD_SALES. There are also links to many other tables ie Shipping, pricing, org etc.
CRMM_BUT_SET0140 - for Sales Group, Sales Office, District
CRMM_BUT_LNK0141 - for Sales Area data
Transaction CRMD_BUS2000115 allows you to see all sales transactions for a BP. CRMD_BUS2000126 shows you activities for selected BP.
Regards
M
Similar Messages
-
Hi,
I built a query with 4 tables inside (load from Oracle DB and two of them are quite big, more than millions of rows). After filtering, I tried to build relationships between tables using Table.Join formula. However, the process took extremly long time to
bring out results (I ended the process after 15 mins' processing). There's a status bar kept updating while the query was processing, which is showed as . I suppose
this is because the query folding didn't working, so PQ had to load all the data to local memory first then do the opertion, instead of doing all the work on the source system side. Am I right? If yes, is there any ways to solve this issue?
Thanks.
Regards,
QilongHi Curt,
Here's the query that I'm refering,
let
Source = Oracle.Database("reporting"),
AOLOT_HISTS = Source{[Schema="GEN",Item="MVIEW$_AOLOT_HISTS"]}[Data],
WORK_WEEK = Source{[Schema="GEN",Item="WORK_WEEK"]}[Data],
DEVICES = Source{[Schema="GEN",Item="MVIEW$_DEVICES"]}[Data],
AO_LOTS = Source{[Schema="GEN",Item="MVIEW$_AO_LOTS"]}[Data],
Filter_WorkWeek = Table.SelectRows(WORK_WEEK, each ([WRWK_YEAR] = 2015) and (([WORK_WEEK] = 1) or ([WORK_WEEK] = 2) or ([WORK_WEEK] = 3))),
Filter_AlotHists = Table.SelectRows(AOLOT_HISTS, each ([STEP_NAME] = "BAKE" or [STEP_NAME] = "COLD TEST-IFLEX" or [STEP_NAME] = "COLD TEST-MFLEX") and ([OUT_QUANTITY] <> 0)),
#"Added Custom" = Table.AddColumn(Filter_AlotHists, "Custom", each Table.SelectRows(Filter_WorkWeek, (table2Row) => [PROCESS_END_TIME] >= table2Row[WRWK_START_DATE] and [PROCESS_END_TIME] <= table2Row[WRWK_END_DATE])),
#"Expand Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"WRWK_YEAR", "WORK_WEEK", "WRWK_START_DATE", "WRWK_END_DATE"}, {"WRWK_YEAR", "WORK_WEEK",
"WRWK_START_DATE", "WRWK_END_DATE"}),
Filter_AolotHists_byWeek = Table.SelectRows(#"Expand Custom", each ([WORK_WEEK] <> null)),
SelectColumns_AolotHists = Table.SelectColumns(Filter_AolotHists_byWeek,{"ALOT_NUMBER", "STEP_NAME", "PROCESS_START_TIME", "PROCESS_END_TIME", "START_QUANTITY", "OUT_QUANTITY", "REJECT_QUANTITY",
"WRWK_FISCAL_YEAR", "WRWK_WORK_WEEK_NO"}),
Filter_Devices= Table.SelectRows(DEVICES, each ([DEPARTMENT] = "TEST1")),
SelectColumns_Devices = Table.SelectColumns(Filter_Devices,{"DEVC_NUMBER", "PCKG_CODE"}),
Filter_AoLots = Table.SelectRows(AO_LOTS, each Text.Contains([DEVC_NUMBER], "MC09XS3400AFK") or Text.Contains([DEVC_NUMBER], "MC09XS3400AFKR2") or Text.Contains([DEVC_NUMBER], "MC10XS3412CHFK") or Text.Contains([DEVC_NUMBER],
"MC10XS3412CHFKR2")),
SelectColumns_AoLots = Table.SelectColumns(Filter_AoLots,{"ALOT_NUMBER", "DEVC_NUMBER", "TRACECODE", "WAFERLOTNUMBER"}),
TableJoin = Table.Join(SelectColumns_AolotHists, "ALOT_NUMBER", Table.PrefixColumns(SelectColumns_AoLots, "AoLots"), "AoLots.ALOT_NUMBER"),
TableJoin1 = Table.Join(TableJoin, "AoLots.DEVC_NUMBER", Table.PrefixColumns(SelectColumns_Devices, "Devices"), "Devices.DEVC_NUMBER")
in
TableJoin1
Could you please give me some hints why it needs so long to process?
Thanks. -
1. How to create an explain plan with rowsource statistics for a complex query that include multiple table joins ?
When multiple tables are involved , and the actual number of rows returned is more than what the explain plan tells. How can I find out what change is needed in the stat plan ?
2. Does rowsource statistics gives some kind of understanding of Extended stats ?You can get Row Source Statistics only *after* the SQL has been executed. An Explain Plan midway cannot give you row source statistics.
To get row source statistics either set STATISTICS_LEVEL='ALL' in the session that executes theSQL OR use the Hint "gather_plan_statistics" in the SQL being executed.
Then use dbms_xplan.display_cursor
Hemant K Chitale -
Oracle query with out using self join
hi friends,
i have one table for exeample PERSTATUS
pk/fK STUDENT NUMBER SUBJECT MARKS STATUS
1 ACCOUNTS 15 RED
1 MATHS 35 YELLOW
1 SCINECE 45 GREEN
2 ACCOUNTS 55 BROWN
2 MATHS 35 YELLOW
2 SCINECE 45 GREEN
3 ACCOUNTS 15 RED
3 MATHS 35 YELLOW
3 SCINECE 45 GREEN
i want students how status is both red and yellow so i am using self join
i want students status is both red and yellow so i am using self join
SELECT PS.STUDENTNUMBER,PS.STATUS,PS.STATUS1 FROM PERSTATUS PS ,PERSTATUS PS1
WHERE PS.STUDENTNUMBER-PS1.STUDENTNUMER
PS.STATUS='RED' AND PS1.STAUTS='YELLOW'
i want students status is both RD and YELLOW AND GREEN so i am using self join( two self joinS}
SELECT PS.STUDENTNUMBER,PS.STATUS,PS.STATUS,PS2.STATUS FROM PERSTATUS PS ,PERSTATUS PS1,PERSTATUS PS2
WHERE PS.STUDENTNUMBER-PS1.STUDENTNUMER AND PS.STUDENTNUMBER-PS2.STUDENTNUMBER
PS.STATUS='RED' AND PS1.STAUTS='YELLOW' AND PS2.STAUTUS='GREEN'
if i require MORE STATUS then more self joins required, is there any alternative to achive this
and if results comes in multiple rows are accepted (since with the above query result will come in single row)
i tried to use group by (studentnumber,status) with status='red' and status='yellow'
but it is not possible could you povidet he solutionHi,
Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data, and the exact results you want from that data. Explain how you get those results from that data.
See the forum FAQ {message:id=9360002}
Here's an example of how to post the sample data:
CREATE TABLE perstatus
( studentnumber NUMBER
, subject VARCHAR2 (10)
, marks NUMBER
, status VARCHAR2 (10)
INSERT INTO perstatus (studentnumber, subject, marks, status)
VALUES (1, 'ACCOUNTS', 15, 'RED');
INSERT INTO perstatus (studentnumber, subject , marks, status)
VALUES (1, 'MATHS', 35, 'YELLOW');
INSERT INTO perstatus (studentnumber, subject, marks, status)
VALUES (1, 'SCINECE', 45, 'GREEN');
INSERT INTO perstatus (studentnumber, subject, marks, status)
VALUES (2, 'ACCOUNTS', 55, 'BROWN');
INSERT INTO perstatus (studentnumber, subject , marks, status)
VALUES (2, 'MATHS', 35, 'YELLOW');
INSERT INTO perstatus (studentnumber, subject, marks, status)
VALUES (2, 'SCINECE', 45, 'GREEN');
INSERT INTO perstatus (studentnumber, subject, marks, status)
VALUES (3, 'ACCOUNTS', 15, 'RED');
INSERT INTO perstatus (studentnumber, subject , marks, status)
VALUES (3, 'MATHS', 35, 'YELLOW');
INSERT INTO perstatus (studentnumber, subject, marks, status)
VALUES (3, 'SCINECE', 45, 'GREEN');You were on the right track, thinking about GROUP BY. You're interested in something about the whole group of rows that has the same studentnumber. Looking at any individual row won't tell you if that row is part of the group you're interested in or not.
If you want to see information about the group as a whole, you can do the whole job with GROUP BY. In this case, studnetnumber is the only thing that an entire group has in common. If you wanted to see the studentnumbers that had both RED and YELLOW, that is:
STUDENTNUMBER
1
3here's one way you could do it:
SELECT studentnumber
FROM perstatus
WHERE status IN ('RED', 'YELLOW')
GROUP BY studentnumber
HAVING COUNT (DISTINCT status) = 2 -- That is, both RED and YELLOW
ORDER BY studentnumber
;But say you wanted to see details about individuals in the group; for example, say we want to see all the columns for students that have all 3 of RED, YELLOW and GREEN, like this:
STUDENTNUMBER SUBJECT MARKS STATUS
1 SCINECE 45 GREEN
1 ACCOUNTS 15 RED
1 MATHS 35 YELLOW
3 SCINECE 45 GREEN
3 ACCOUNTS 15 RED
3 MATHS 35 YELLOWWe used the aggregate COUNT function earlier, but aggregate functions require collapsing the results down to one row per group.
However, most of the aggregate functions, like COUNT, have analytic counterparts, that can give the same results without collapsing the result set. Here's one way to get the results above, using the analytic COUNT function:
WITH got_cnt AS
SELECT studentnumber, subject, marks, status
, COUNT ( DISTINCT CASE
WHEN status IN ('RED', 'YELLOW', 'GREEN')
THEN status
END
) OVER (PARTITION BY studentnumber) AS cnt
FROM perstatus
SELECT studentnumber, subject, marks, status
FROM got_cnt
WHERE cnt = 3
ORDER BY studentnumber
, status
; -
"cannot perform a DML operation inside a query" error when using table func
hello please help me
i created follow table function when i use it by "select * from table(customerRequest_list);"
command i receive this error "cannot perform a DML operation inside a query"
can you solve this problem?
CREATE OR REPLACE FUNCTION customerRequest_list(
p_sendingDate varchar2:=NULL,
p_requestNumber varchar2:=NULL,
p_branchCode varchar2:=NULL,
p_bankCode varchar2:=NULL,
p_numberOfchekbook varchar2:=NULL,
p_customerAccountNumber varchar2:=NULL,
p_customerName varchar2:=NULL,
p_checkbookCode varchar2:=NULL,
p_sendingBranchCode varchar2:=NULL,
p_branchRequestNumber varchar2:=NULL
RETURN customerRequest_nt
PIPELINED
IS
ob customerRequest_object:=customerRequest_object(
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
condition varchar2(2000 char):=' WHERE 1=1 ';
TYPE rectype IS RECORD(
requestNumber VARCHAR2(32 char),
branchRequestNumber VARCHAR2(32 char),
branchCode VARCHAR2(50 char),
bankCode VARCHAR2(50 char),
sendingDate VARCHAR2(32 char),
customerAccountNumber VARCHAR2(50 char),
customerName VARCHAR2(200 char),
checkbookCode VARCHAR2(50 char),
numberOfchekbook NUMBER(2),
sendingBranchCode VARCHAR2(50 char),
numberOfIssued NUMBER(2)
rec rectype;
dDate date;
sDate varchar2(25 char);
TYPE curtype IS REF CURSOR; --RETURN customerRequest%rowtype;
cur curtype;
my_branchRequestNumber VARCHAR2(32 char);
my_branchCode VARCHAR2(50 char);
my_bankCode VARCHAR2(50 char);
my_sendingDate date;
my_customerAccountNumber VARCHAR2(50 char);
my_checkbookCode VARCHAR2(50 char);
my_sendingBranchCode VARCHAR2(50 char);
BEGIN
IF NOT (regexp_like(p_sendingDate,'^[[:digit:]]{4}/[[:digit:]]{2}/[[:digit:]]{2}$')
OR regexp_like(p_sendingDate,'^[[:digit:]]{4}/[[:digit:]]{2}/[[:digit:]]{2}[[:space:]]{1}[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}$')) THEN
RAISE_APPLICATION_ERROR(-20000,cbdpkg.get_e_m(-1,5));
ELSIF (p_sendingDate IS NOT NULL) THEN
dDate:=TO_DATE(p_sendingDate,'YYYY/MM/DD hh24:mi:ss','nls_calendar=persian');
dDate:=trunc(dDate);
sDate:=TO_CHAR(dDate,'YYYY/MM/DD hh24:mi:ss');
condition:=condition|| ' AND ' || 'sendingDate='||'TO_DATE('''||sDate||''',''YYYY/MM/DD hh24:mi:ss'''||')';
END IF;
IF (p_requestNumber IS NOT NULL) AND (cbdpkg.isspace(p_requestNumber)=0) THEN
condition:=condition|| ' AND ' || ' requestNumber='||p_requestNumber;
END IF;
IF (p_bankCode IS NOT NULL) AND (cbdpkg.isspace(p_bankCode)=0) THEN
condition:=condition|| ' AND ' || ' bankCode='''||p_bankCode||'''';
END IF;
IF (p_branchCode IS NOT NULL) AND (cbdpkg.isspace(p_branchCode)=0) THEN
condition:=condition|| ' AND ' || ' branchCode='''||p_branchCode||'''';
END IF;
IF (p_numberOfchekbook IS NOT NULL) AND (cbdpkg.isspace(p_numberOfchekbook)=0) THEN
condition:=condition|| ' AND ' || ' numberOfchekbook='''||p_numberOfchekbook||'''';
END IF;
IF (p_customerAccountNumber IS NOT NULL) AND (cbdpkg.isspace(p_customerAccountNumber)=0) THEN
condition:=condition|| ' AND ' || ' customerAccountNumber='''||p_customerAccountNumber||'''';
END IF;
IF (p_customerName IS NOT NULL) AND (cbdpkg.isspace(p_customerName)=0) THEN
condition:=condition|| ' AND ' || ' customerName like '''||'%'||p_customerName||'%'||'''';
END IF;
IF (p_checkbookCode IS NOT NULL) AND (cbdpkg.isspace(p_checkbookCode)=0) THEN
condition:=condition|| ' AND ' || ' checkbookCode='''||p_checkbookCode||'''';
END IF;
IF (p_sendingBranchCode IS NOT NULL) AND (cbdpkg.isspace(p_sendingBranchCode)=0) THEN
condition:=condition|| ' AND ' || ' sendingBranchCode='''||p_sendingBranchCode||'''';
END IF;
IF (p_branchRequestNumber IS NOT NULL) AND (cbdpkg.isspace(p_branchRequestNumber)=0) THEN
condition:=condition|| ' AND ' || ' branchRequestNumber='''||p_branchRequestNumber||'''';
END IF;
dbms_output.put_line(condition);
OPEN cur FOR 'SELECT branchRequestNumber,
branchCode,
bankCode,
sendingDate,
customerAccountNumber ,
checkbookCode ,
sendingBranchCode
FROM customerRequest '|| condition ;
LOOP
FETCH cur INTO my_branchRequestNumber,
my_branchCode,
my_bankCode,
my_sendingDate,
my_customerAccountNumber ,
my_checkbookCode ,
my_sendingBranchCode;
EXIT WHEN (cur%NOTFOUND) OR (cur%NOTFOUND IS NULL);
BEGIN
SELECT requestNumber,
branchRequestNumber,
branchCode,
bankCode,
TO_CHAR(sendingDate,'yyyy/mm/dd','nls_calendar=persian'),
customerAccountNumber ,
customerName,
checkbookCode ,
numberOfchekbook ,
sendingBranchCode ,
numberOfIssued INTO rec FROM customerRequest FOR UPDATE NOWAIT;
--problem point is this
EXCEPTION
when no_data_found then
null;
END ;
ob.requestNumber:=rec.requestNumber ;
ob.branchRequestNumber:=rec.branchRequestNumber ;
ob.branchCode:=rec.branchCode ;
ob.bankCode:=rec.bankCode ;
ob.sendingDate :=rec.sendingDate;
ob.customerAccountNumber:=rec.customerAccountNumber ;
ob.customerName :=rec.customerName;
ob.checkbookCode :=rec.checkbookCode;
ob.numberOfchekbook:=rec.numberOfchekbook ;
ob.sendingBranchCode:=rec.sendingBranchCode ;
ob.numberOfIssued:=rec.numberOfIssued ;
PIPE ROW(ob);
IF (cur%ROWCOUNT>500) THEN
CLOSE cur;
RAISE_APPLICATION_ERROR(-20000,cbdpkg.get_e_m(-1,4));
EXIT;
END IF;
END LOOP;
CLOSE cur;
RETURN;
END;Now what exactly would be the point of putting a SELECT FOR UPDATE in an autonomous transaction?
I think OP should start by considering why he has a function with an undesirable side effect in the first place. -
Table join and Logical databasein a same query
Hi Experts,
I have an existing query which is created using table join. I now want to add a logical database in the same infoset.
Is it possible to add a logical database in the same infoset?
Regards,
PrakharHi Prakhar,
If you see the below scren, you can use data source either Table join using basis table or Logical database.
but if you need ldb with some addition table field then you can data retrieval by program step or you can use LDB with doing some code in inside your infoset.
Regards,
Prasenjit -
Hi,
in 8.1.7 ,is there any query that returns most used tables ? How to know most used tables ?
Thank you.Query for frequently used tables?
Frequently used tables
may be helpful to you.
Regards
Girish Sharma -
I am trying to develop a query in MS Access 2010 to join two tables using three joins, one of which is a (between) date range. The tables are contained in Access. The reason
the tables are contained in access because they are imported from different ODBC warehouses and the data is formatted for uniformity. I believe this cannot be developed using MS Visual Query Designer. I think writing a query in SQL would be suiting this project.
ABCPART links to XYZPART. ABCSERIAL links to XYZSERIAL. ABCDATE links to (between) XYZDATE1 and ZYZDATE2.
[ABCTABLE]
ABCORDER
ABCPART
ABCSERIAL
ABCDATE
[ZYXTABLE]
XYZORDER
XYZPART
XYZSERIAL
XYZDATE1
XYZDATE2Thank you for the looking at the post. The actual table names are rather ambiguous. I renamed them so it would make more sense. I will explain more and give the actual names. What I do not have is the actual data in the table. That is something I don't have
on this computer. There are no "Null" fields in either of the tables.
This table has many orders (MSORDER) that need to match one order (GLORDER) in GLORDR. This is based on MSPART joined to GLPART, MSSERIAL joined to GLSERIAL, and MSOPNDATE joined if it falls between GLSTARTDATE and GLENDDATE.
[MSORDR]
MSORDER
MSPART
MSSERIAL
MSOPNDATE
11111111
4444444
55555
2/4/2015
22222222
6666666
11111
1/6/2015
33333333
6666666
11111
3/5/2015
This table has one order for every part number and every serial number.
[GLORDR]
GLORDER
GLPART
GLSERIAL
GLSTARTDATE
GLENDDATE
ABC11111
444444
55555
1/2/2015
4/4/2015
ABC22222
666666
11111
1/5/2015
4/10/2015
AAA11111
555555
22222
3/2/2015
4/10/2015
Post Query table
GLORDER
MSORDER
GLSTARTDATE
GLENDDATE
MSOPNDATE
ABC11111
11111111
1/2/2015
4/4/2015
2/4/2015
ABC22222
22222222
1/5/2015
4/10/2015
1/6/2015
ABC22222
33333333
1/5/2015
4/10/2015
3/5/2015
This is the SQL minus the between date join.
SELECT GLORDR.GLORDER, MSORDR.MSORDER, GLORDR.GLSTARTDATE, GLORDR.GLENDDATE, MSORDR.MSOPNDATE
FROM GLORDR INNER JOIN MSORDR ON (GLORDR.GLSERIAL = MSORDR.MSSERIAL) AND (GLORDR.GLPART = MSORDR.MSPART); -
How to use outer join condition in my below query.
Hi All,
How to use outer join condition in my below query.
In the table APPS_JP.GEDIS_OFFER_HEADER goh I have more records
in the table APPS_JP.GEDIS_ORDER_BUILDS gob I have less number of records.
I want all the records from APPS_JP.GEDIS_OFFER_HEADER goh
including other conditions.
I have tried goh.OFFER_NO=gob.OFFER_NO(+) but same result.
[code]SELECT GOH.ORIG_SYSTEM,
gsp.USER_NAME,
goh.ORDER_NO,
goh.OMEGA_ORDER_NUMBER,
goh.ORDER_TYPE,
gc.CUSTOMER_ID,
gc.OMEGA_CUSTOMER_NUMBER,
CASE WHEN gc.PRIVATE = 'N' THEN gc.CUSTOMER_NAME ELSE '' END
AS COMPANY_NAME,
goh.ORDER_STATUS,
goh.TOTAL_SELLING_PRICE,
goh.TOTAL_MARGIN,
ga1.ADDRESS1
|| ','
|| ga1.ADDRESS2
|| ','
|| ga1.ADDRESS3
|| ','
|| ga1.POSTAL_CODE
|| ','
|| ga1.CITY
AS SHIPPING_ADDRESS,
ga2.ADDRESS1
|| ','
|| ga2.ADDRESS2
|| ','
|| ga2.ADDRESS3
|| ','
|| ga2.POSTAL_CODE
|| ','
|| ga2.CITY
AS BILLING_ADDRESS,
ga.ADDRESS_ID,
gol.DESCRIPTION,
APPS_JP.TZ.to_local_date (goh.OFFER_DATE, goh.OFFER_DATE_UTC)
AS OFFER_DATE,
gc.LEVEL_8,
goh.NO_OF_BUILDS,
gob.SFDC_ID,
goh.PURCHASE_ORDER_NO AS PO,
gc1.CUSTOMER_NAME AS END_USAGE,
gol.LOB,
goh.TOTAL_MARGIN_PCT,
goh.TOTAL_DISCOUNT,
goh.TOTAL_DISCOUNT_PCT
FROM APPS_JP.GEDIS_OFFER_HEADER goh,
APPS_JP.GEDIS_ORDER_BUILDS gob,
APPS_JP.GEDIS_ORDER_LINES gol,
APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER gorc,
APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER ship,
APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER bill,
APPS_JP.GEDIS_CUSTOMER gc,
APPS_JP.GEDIS_CUSTOMER gc1,
APPS_JP.GEDIS_CONTACT gct,
APPS_JP.GEDIS_ADDRESS ga,
APPS_JP.GEDIS_ADDRESS_NORM ga1,
APPS_JP.GEDIS_ADDRESS_NORM ga2,
(SELECT DISTINCT SALESPERSON_ID, USER_NAME
FROM APPS_JP.GEDIS_SALESPERSON
WHERE SALESPERSON_ID IN
(SELECT TO_NUMBER (COLUMN_VALUE) AS SALESPERSON_ID
FROM TABLE (APPS_GLOBAL.SplitString ('337309'))))
gsp
WHERE goh.ORDER_NO <> 0
AND goh.OFFER_NO <> 0
AND goh.OFFER_NO=gol.OFFER_NO
AND gol.BUILD_NO = 1
AND gol.LINE_NO = 1
AND goh.OFFER_NO=gob.OFFER_NO
AND gob.BUILD_NO = 1
AND goh.OFFER_NO = gorc.OFFER_NO
AND gct.CONTACT_ID = gorc.CONTACT_ID
AND ga.CUSTOMER_ID = gc.CUSTOMER_ID
AND ga.PRIMARY = 'Y'
AND goh.LEAD_SALESPERSON=gsp.SALESPERSON_ID
AND goh.OFFER_NO = ship.OFFER_NO
AND ship.RELATION_TYPE = 'SHIP'
AND ga1.ADDRESS_ID = ship.ADDRESS_ID
AND ga1.CUSTOMER_ID = gc1.CUSTOMER_ID
AND goh.OFFER_NO = bill.OFFER_NO
AND bill.RELATION_TYPE = 'BILL'
AND ga2.ADDRESS_ID = bill.ADDRESS_ID
AND goh.OFFER_DATE BETWEEN APPS_JP.TZ.LOCAL_TO_DB_DATE (
SYSDATE - 30
AND APPS_JP.TZ.LOCAL_TO_DB_DATE (SYSDATE)
AND gorc.RELATION_TYPE = 'BASE'
AND gorc.CUSTOMER_ID = gc.CUSTOMER_ID
AND goh.SALES_CHANNEL = gc.SALES_CHANNEL
AND gc.SALES_CHANNEL = 'SMB'
AND goh.LEAD_SALESPERSON IN (goh.CREATED_BY, goh.LEAD_SALESPERSON)
ORDER BY goh.OFFER_NO;[/code]
Please help me how to use this outer join condition.
Thanks in advance.Hi,
If you want all the rows from goh, then you don't want any conditions like goh.OFFER_NO <> 0.
Make all the joins to goh outer joins, and make all conditions that apply to any tables joined to goh (or to tables joined to them) part of the join condition, like this:
FROM APPS_JP.GEDIS_OFFER_HEADER goh
LEFT OUTER JOIN APPS_JP.GEDIS_ORDER_BUILDS gob ON gob.OFFER_NO = goh.OFFER_NO
AND gob.BUILD_NO = 1
LEFT OUTER JOIN APPS_JP.GEDIS_ORDER_LINES gol ON gol.OFFER_NO = goh.OFFER_NO
AND gol.BUILD_NO = 1
AND gol.LINE_NO = 1
LEFT OUTER JOIN APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER
gorc ...
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Simplify the problem as much as possible. For example, do you really need all those tables to show what the problem is? Of course, you need them in tyour real query, but if you understand a solution that only involves 4 or 5 tables, you'll know how to apply it to any number of tables.
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 https://forums.oracle.com/message/9362002#9362002 -
SQ01 Output From Joining VBSEGK and VBSEGS tables-1 line of output per DOC
I setup a query using SQ01 which uses tables VBSEGK and VBSEGS ( parked documents). The VBSEGS table has multiple lines per document in that there are multiple G/L accounts, cost centers and amounts in order to distribute expense acorss multiple cost centers from one vendor's invoice. When I execute the query only the first line item in the VBSEGS table appears and the remaining lines do not appear. Any insight to get all line items for each document from the VCSEGS table to appear will be appreciated.
Hi,
By default four links will be established between VBSEGK and VBESGS.
AUSBK
BELNR
GJAHR
BZKEY (This link should be removed for getting all the records)
However, you get the line items only if documents exist in both the tables. Apart from that, if two line items in one table and three line items in another table, you will get only three line items in the report. You need to select fields related to VBSEGK and VBSEGS tables.
Please provide me more information on your exact requirement. I can confirm you whether this is possible by way of query.
Best Regards,
Madhu -
Help! Howto use the join function in a query with select distinct ?
Hi!
I have 2 tables. I want to select only 1 painting of each artists.
select distinct idartist
from tbl_artworks
where blah blah blah
order by rand()
how does the "join" function work for add: name, lastname, title, image and much more... i try... but i fail...
tbl_artists
idartist
name
lastname
1
Paul
Gaugain
2
Vincent
Van Gogh
3
Pablo
Picasso
tbl_artworks
idartwork
idartist
title
image
1
1
days of gods
image1.jpg
2
2
sunflower
image2.jpg
3
3
Dora maar au chat
image3.jpg
4
2
Sky
image4.jpg
5
3
La vie
image5.jpgGetting a single random image for each probably requires a combination of sql and cf. It would take someone smarter than me to do it with sql alone. I would probably try something like this:
1. Run a database query that gets all the images from all the artists.
2. Run a Q of Q that gets a distinct list of artist ids.
3. Loop through that list and run a Q of Q to get all the images for that artist.
4. Still in that loop, use randrange (1 to the recordcount) to select a random record from your Q of Q -
3 Table Joins -- Need a more efficient Query
I need a 3 table join but need to do it more efficiently than I am currently doing. The query is taking too long to execute (in excess of 20 mins. These are huge tables with 10 mil + records). Here is what the query looks like right now. I need 100 distinct acctnum from the below query with all the conditions as requirements.
THANKS IN ADVANCE FOR HELP!!!
SELECT /*+ parallel */
FROM (SELECT /*+ parallel */ DISTINCT (a.acctnum),
a.acctnum_status,
a.sys_creation_date,
a.sys_update_date,
c.comp_id,
c.comp_lbl_type,
a.account_sub_type
FROM account a
LEFT JOIN
company c
ON a.comp_id = c.comp_id AND c.comp_lbl_type = 'IND',
subaccount s
WHERE a.account_type = 'I'
AND a.account_status IN ('O', 'S')
and s.subaccount_status in ('A','S')
AND a.account_sub_type NOT IN ('G', 'V')
AND a.SYS_update_DATE <= SYSDATE - 4 / 24)
where ROWNUM <= 100 ;Hi,
Whenever you have a question, post CREATE TABLE and INSERT statements for a little sample data, and the results you want from that data. Explain how you get those results from that data.
Simplify the problem, if possible. If you need 100 distinct rows, post a problem where you only need, say, 3 distinct rows. Just explain that you really need 100, and you'll get a solution that works for either 3 or 100.
Always say which version of Oracle you're using (e.g. 11.2.0.3.0).
See the forum FAQ: https://forums.oracle.com/message/9362002
For tuning problems, also see https://forums.oracle.com/message/9362003
Are you sure the query you posted is even doing what you want? You're cross-joining s to the other tables, producing all possible combinations of rows, and then picking 100 of those in no particular order (not even random order). That's not necessarily wrong, but it certainly is suspicious.
If you're only interested in 100 rows, there's probably some way to write the query so that it picks 100 rows from the big tables first. -
Hi All,
I am a newbie for T-Sql, I came across a SP where multiple tables are engaged using multiple joins but the where clause contain a column field without any table reference and assigned for an incoming variable,like
where 'UserId = @UserId'
instead - no table reference like 'a.UserId = @Userid' ............ Can any please do refer to me any material that clears my mind regarding such issue................... help is appreciated.
Thank You.As suggested above, use table alias with columns for unique referencing and to make the code easier to read.
BOL example for table aliasing:
USE AdventureWorks;
GO
SELECT S.CustomerID, S.Name AS Store, A.City, SP.Name AS State, CR.Name
AS CountryRegion
FROM Sales.Store AS S
JOIN Sales.CustomerAddress AS CA ON CA.CustomerID = S.CustomerID
JOIN Person.Address AS A ON A.AddressID = CA.AddressID
JOIN Person.StateProvince SP ON
SP.StateProvinceID = A.StateProvinceID
JOIN Person.CountryRegion CR ON
CR.CountryRegionCode = SP.CountryRegionCode
ORDER BY S.CustomerID ;
GO
GO
LINK:
http://technet.microsoft.com/en-us/library/ms124824(v=sql.100).aspx
Check the use of TABLE ALIASes and COLUMN ALIASes in the following blog:
http://www.sqlusa.com/bestpractices2005/organizationtree/
Without the use of aliases the code would become unreadable.
Kalman Toth Database & OLAP Architect
Free T-SQL Scripts
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
Using case when statement in the select query to create physical table
Hello,
I have a requirement where in I have to execute a case when statement with a session variable while creating a physical table using a select query. let me explain with an example.
I have a physical table based on a select table with one column.
SELECT 'VALUEOF(NQ_SESSION.NAME_PARAMETER)' AS NAME_PARAMETER FROM DUAL. Let me call this table as the NAME_PARAMETER table.
I also have a customer table.
In my dashboard that has two pages, Page 1 contains a table with the customer table with column navigation to my second dashboard page.
In my second dashboard page I created a dashboard report based on NAME_PARAMETER table and a prompt based on customer table that sets the NAME_ PARAMETER request variable.
EXECUTION
When i click on a particular customer, the prompt sets the variable NAME_PARAMETER and the NAME_PARAMETER table shows the appropriate customer.
everything works as expected. YE!!
Now i created another table called NAME_PARAMETER1 with a little modification to the earlier table. the query is as follows.
SELECT CASE WHEN 'VALUEOF(NQ_SESSION.NAME_PARAMETER)'='Customer 1' THEN 'TEST_MART1' ELSE TEST_MART2' END AS NAME_PARAMETER
FROM DUAL
Now I pull in this table into the second dashboard page along with the NAME_PARAMETER table report.
surprisingly, NAME_PARAMETER table report executes as is, but the other report based on the NAME_PARAMETER1 table fails with the following error.
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 16001] ODBC error state: S1000 code: 1756 message: [Oracle][ODBC][Ora]ORA-01756: quoted string not properly terminated. [nQSError: 16014] SQL statement preparation failed. (HY000)
SQL Issued: SET VARIABLE NAME_PARAMETER='Novartis';SELECT NAME_PARAMETER.NAME_PARAMETER saw_0 FROM POC_ONE_DOT_TWO ORDER BY saw_0
If anyone has any explanation to this error and how we can achieve the same, please help.
Thanks.Hello,
Updates :) sorry.. the error was a stupid one.. I resolved and I got stuck at my next step.
I am creating a physical table using a select query. But I am trying to obtain the name of the table dynamically.
Here is what I am trying to do. the select query of the physical table is as follows.
SELECT CUSTOMER_ID AS CUSTOMER_ID, CUSTOMER_NAME AS CUSTOMER_NAME FROM 'VALUEOF(NQ_SESSION.SCHEMA_NAME)'.CUSTOMER.
The idea behind this is to obtain the data from the same table from different schemas dynamically based on what a session variable. Please let me know if there is a way to achieve this, if not please let me know if this can be achieved in any other method in OBIEE.
Thanks. -
In which condition Table valued function should prefer over SP except use in joins?
Hi,
My requirements is:
Entity framework needs to call DB object (TVF or SP), which will provide some data to them and they'll work on it at app level.
DB object would be simple, one result set, it will join 5 tables and get around 30 columns to them. it would be parameterized query so can't use view.
Now my question is what DB object would be best to use, table valued function or store procedure. and why?
I google on it, I find some interesting links (example http://technet.microsoft.com/en-us/library/ms187650(v=sql.105).aspx)
they mentioned conditions to convert SP to TVF but not mentioned the reason, why I should convert?
Both have same cache plans strategy. SP has so many advantages over TVF, but I don't see any technical advantage of TVF over SP except it can be use in joins or so.
so In short my question is, why I can't use SP in all cases, why I would use TVF?, and which Table valued or multi-valued?
would appreciate your time and response.According to a few recent blogs you should be able to use TVP or stored procedure with EF 6.1.2 with ease. In our application we haven't switched yet to 6.1.2 (we're using 6.0.0) and there is no support for stored procedures or functions so we use StoreQuery.
I am wondering if you can share your experience of using EF with SP or TVP (and document the steps).
I am also wondering as how exactly it's working behind the scenes and where the full query is taking place. Say, in our case we may want to add some extra conditions after retrieving a set using, say, SP. Would the final query execute on the client (e.g.
SP executed on the server, result returned and then extra conditions executed on the "client")?
As I said, right now we're using StoreQuery which means that our extra conditions must be case - sensitive as opposed to SQL Server case insensitive. So, if someone already tried that scenario and can tell me how exactly it works, I would appreciate it.
Another question about EF - I defined a property as
[Column(TypeName = "varchar")]
public string PhoneNumber { get; set; } // area code + phone
and in the LINQ query as
var query = db.Accounts.Select(a => new AccountsList
AcctName = a.AcctName,
Contact = a.Contact,
FullName = a.FullName,
AreaCode = a.AreaCode,
Phone = a.Phone,
Hidden = a.Hide,
Hide = a.Hide,
PhoneNumber = a.AreaCode.Trim() + a.Phone.Trim(),
AcctTypeId = a.AcctTypeId
and I see that it's translated into CASE AreaCode IS NULL THEN N'' ELSE RTRIM(LTRIM(areaCode)) END + ...
My question is - why EF does it if there is no mentioning at all in the class as how NULL is supposed to be treated. Is it a bug?
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles
Maybe you are looking for
-
HP Officejet Pro L7590 networking problem
Hi! I have the following problem: I have an Officejet Pro L7590 All-in-one printer. It is connected to my wlan router (ASUS WL-500G Premium) through its ethernet port. I have two desktop PCs, i've installed, and using this printer on them without pro
-
IE8 on XP shuts down on first print of Crystal Report using ActiveX Viewer
Environment: u2022 Business Objects Enterprise XI 3.1 SP3 FP 3.5 u2022 Tomcat 5.5 u2022 Windows Server 2003 u2022 JDK Version: 1.6 u2022 Internet Explorer 8 - compatibility mode u2022 client machines Windows XP Professional SP3 Issue: The browser shu
-
Hi guys, I have written a neural network with a standard back-propagation learning algroithm which aims to learn a XOR logic function. However, it doesn't seem to work as expected. If i present all patterns to it (0,0, 1,1, 0,1, 1,0) the weights stay
-
Business Package on Producer and Consumer in a FPN
Hi Gurus, I need to know if we need to install the Same Business packages on both the producer and consumer or is it enough to install the Business Package only on the producer.... Regards!
-
Minor Dents that I would like to be fixed
Hi, I recently just bought my MacBook Air 13 from someone and my computer works perfectly fine but there is a few minor dents on top of the computer that has been bugging me and I would like to know if Apple can repair it even if I don't have a warra