update issue

Select works but when I do update I get error

UPDATE DIM t1
SET CURR_FLG=
SELECT
CASE WHEN A.RN=1 THEN 'Y' ELSE 'N' END as CURR_FLG
FROM
(
SELECT  
EMPLID,
EMPL_RCD,
EFFDT,
LST_ASGN_START_DT,
EMPL_STATUS,
ROW_NUMBER() OVER (PARTITION BY EMPLID,EMPL_RCD ORDER BY EFFDT DESC) AS RN
FROM DIM
WHERE EFFDT<=SYSDATE)A
WHERE t1.JOB_SID=A.JOB_SID
sam2929Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
What is the error?

When I see an update like this, I think of MERGE:
http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_9016.htm#SQLRF01606

There are many examples out there.
slightwv (䄆 Netminder) Commented:
I just re-read the update statement.  Since you are updating the same table you are selecting from MERGE becomes more difficult.
sam2929Author Commented:
Error at Command Line : 58 Column : 1
Error report -
SQL Error: ORA-00936: missing expression
00936. 00000 -  "missing expression"
*Cause:    
*Action:
slightwv (䄆 Netminder) Commented:
Try wrapping the select in parenthesis:
UPDATE DIM t1
 SET CURR_FLG=
 (SELECT
 CASE WHEN A.RN=1 THEN 'Y' ELSE 'N' END as CURR_FLG
 FROM
 (
 SELECT  
 EMPLID,
 EMPL_RCD,
 EFFDT,
 LST_ASGN_START_DT,
 EMPL_STATUS,
 ROW_NUMBER() OVER (PARTITION BY EMPLID,EMPL_RCD ORDER BY EFFDT DESC) AS RN
 FROM DIM
 WHERE EFFDT<=SYSDATE)A
 WHERE t1.JOB_SID=A.JOB_SID 
)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
awking00Information Technology SpecialistCommented:
Can you provide some sample data and the expected results from that data?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.