|
Re: HELP Please!!!! [message #186603 is a reply to message #186597] |
Tue, 08 August 2006 12:52 |
scottwmackey
Messages: 515 Registered: March 2005
|
Senior Member |
|
|
This is what the query would look like if it weren't dynamic. I don't have the time to mess with all of formatting but you can get the feeling for what you need to do.
UPDATE v_table_name
SET v_table_name.fieldx = (SELECT CASE
WHEN v_table_name
.fieldrp NOT IN
(', ' val1 ', ', ', ' val2 ', ', ', ' val3 ', ', ', ' val4 ', ') THEN
', ' ', '
WHEN reference_table. fieldf IS NOT NULL AND v_table_name.yrmo_dt >= ', '
01 - jan - 2005 ', ' THEN
reference_table.fieldf
ELSE
', ' unk ', '
END
FROM reference_table
WHERE v_table_name.fieldrp = reference_table.fieldrp
AND reference_table.sbc_fielducd = v_table_name.fieldre
AND reference_table.fieldactive = ', ' y ', ')
WHERE EXISTS (SELECT *
FROM reference_table
WHERE v_table_name.fieldrp = reference_table.fieldrp
AND reference_table.sbc_fielducd = v_table_name.fieldre
AND reference_table.fieldactive = ', ' y ', ');;
|
|
|
|
|
Re: HELP Please!!!! [message #186648 is a reply to message #186631] |
Tue, 08 August 2006 18:08 |
aa0609
Messages: 3 Registered: August 2006 Location: IL
|
Junior Member |
|
|
Let me try to explain what I am trying to accomplish. I need to update a field of an existing table based on the values of a reference table and if there is no match on the reference table then update field with UNK.
I was doing that in SQL server with no problems by using a case statement and a left outer join. We are migrating to Oracle and my SQL server proc will not work on Oracle if I leave the left outer join I get a “single row subquery returns more than one row” error….If I take the left outer join out and just modify the where clause to where ' || v_TABLE_NAME ||'.fieldrp = reference_table.fieldrp ' ||
' AND reference_table.sbc_fielducd = '||v_TABLE_NAME ||'.fieldre ' ||
' AND reference_table.fieldactive = ''Y'') then I get a ORA-01407: cannot update () to NULL for those rows that don’t have a match on the reference table..
I am not sure how to accomplish this???
|
|
|