Solved

Conditional Join

Posted on 2012-08-28
3
365 Views
Last Modified: 2012-08-28
Hello experts,

I have this conditional join right here, thanks to the help of the community yesterday

INSERT INTO shipping(sdate, rec_wh, shipping, item)
    SELECT ship_date, receiver_warehouse, ord, custitemcode
      FROM wag
     WHERE     custitemcode = 'SOME ITEM'
           AND (SELECT SUM(ord)
                  FROM recinc
                 WHERE in_item = 'SOME ITEM') = (SELECT SUM("tSHIPPING")
                                                   FROM trans
                                                  WHERE "tITEM" = 'SOME ITEM');

Open in new window


While this achieves what I am trying to do when i use the variable 'SOME ITEM'

I need this to be accomplished on all items in that column that match the above statement. I have tried different variations of the above and it does not work


so lets say in columns, IN_ITEM and t_ITEM have 'SOME ITEM' and other items (eg, 'some item2' 'some item3' etc etc

i want this to happen to all rows where column data matches
0
Comment
Question by:futureDBA
3 Comments
 
LVL 13

Accepted Solution

by:
MrBullwinkle earned 500 total points
ID: 38341768
I'm not really sure I follow what you're asking, but does the following work?  I replaced SOME ITEM, with a reference to CustItemCode, and removed that filter.  You also had quotes around field names, which I removed.

INSERT INTO shipping(sdate, rec_wh, shipping, item)
    SELECT ship_date, receiver_warehouse, ord, custitemcode
      FROM wag
           WHERE (SELECT SUM(ord)
                  FROM recinc
                 WHERE in_item = wag.custitemcode) = (SELECT SUM(tSHIPPING)
                                                   FROM trans
                                                  WHERE tITEM = wag.custitemcode);
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 38341790
tITEM and tSHIPPING are mixed case, you'll need to restore the quotes taken out above


SUM("tSHIPPING")

WHERE "tITEM" = wag.custitemcode);


otherwise oracle will treat them as columns with names TSHIPPING and TITEM which don't exist in your table


also note, if you still want to apply a filter to the wag table, then apply it there by adding a clause like this to end of the query...

AND wag.custitemcode in ('SOMEITEM','some_other_item','a_third_ITEM')
0
 

Author Closing Comment

by:futureDBA
ID: 38342123
Thank You sir, perfect
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now