Solved

Conditional Join

Posted on 2012-08-28
3
362 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
Comment Utility
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
Comment Utility
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
Comment Utility
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.

Join & Write a Comment

Suggested Solutions

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to recover a database from a user managed backup

762 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

6 Experts available now in Live!

Get 1:1 Help Now