Note that there are some explanatory texts on larger screens.

plurals
  1. POORACLE: INSERT SELECT FROM 2 views and value from param
    primarykey
    data
    text
    <p>I'm trying to insert some fields into MYTABLE from views MYVIEW1 and MYVIEW2 and then add a value from a parameter (this is part of a stored procedure) for UPDATED_BY, SYSDATE for UPDATED_ON. How can I correctly do this with INSERT SELECT or some other way entirely?</p> <pre><code>MYVIEW1 +------+----+-----+-----------+---------+ | YR | MO | QTR | USER_CODE | MO_PERF | +------+----+-----+-----------+---------+ | 2012 | 1 | 1 | 1099 | 89 | | 2012 | 2 | 1 | 1099 | 86 | | 2012 | 3 | 1 | 1099 | 95 | +------+----+-----+-----------+---------+ MYVIEW2 +------+-----+-----------+----------+ | YR | QTR | USER_CODE | QTR_PERF | +------+-----+-----------+----------+ | 2012 | 1 | 1099 | 90 | +------+-----+-----------+----------+ MYTABLE +------+-----+-----------+---------+---------+---------+---------+-------------+------------+ | YR | QTR | USER_CODE | MO1_PCT | MO2_PCT | MO3_PCT | INC | UPDATED_BY | UPDATED_ON | +------+-----+-----------+---------+---------+---------+---------+-------------+------------+ | 2012 | 1 | 1099 | 89 | 86 | 95 | 7000 | SAMPLE NAME | 01/16/2013 | +------+-----+-----------+---------+---------+---------+---------+-------------+------------+ INSERT INTO MYTABLE (YR,QTR,USER_CODE,MO1_PCT,MO2_PCT,MO3_PCT,INC,UPDATED_BY,UPDATED_ON) SELECT b.YR,b.QTR,b.USER_CODE,b.MO1_PCT,b.MO2_PCT,b.MO3_PCT,c.INC FROM MYVIEW1 b, MYVIEW2 c </code></pre> <p>How do I insert values for (first month of QTR's MO_PERF) as MO1_PCT and (second month of QTR's MO_PERF) as MO2_PCT and (last month of QTR's MO_PERF) as MO3_PCT, making sure that I've inserted the right month within the right quarter and year.And then check if the MO_PERF values of each month has reached at least 85, else set INC as NULL.</p> <pre><code>,CASE WHEN MO1_PCT&gt;=85 AND MO2_PCT&gt;=85 AND MO3_PCT&gt;=85 THEN 7000 ELSE NULL END INC </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload