?
Solved

Conditional Join

Posted on 2012-08-28
3
Medium Priority
?
370 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Accepted Solution

by:
Ryan earned 2000 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 74

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

765 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