View previous topic :: View next topic
|
Author |
Message |
sandip_mainframe Warnings : 2 New User
Joined: 20 Sep 2006 Posts: 63 Location: pune
|
|
|
|
Hi All,
My requirement is that I need to Update one field for two different condtions.
UPDATE TABLE
SET REQ_STA_CD = '6'
WHERE ENROLL_TYPE = 'R'
UPDATE TABLE
SET REQ_STA_CD = '7'
WHERE ENROLL_TYPE = 'V'
Is it possible to Update it in a single query ? If it is Please provide me the query.
Thanks,
Sandip Walsinge |
|
Back to top |
|
|
belchoff
New User
Joined: 21 Oct 2009 Posts: 4 Location: UK
|
|
|
|
Have you heard about IN clause?
check it pls (google / manuals). |
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
Sandip,
You can do it in the following way.
Code: |
UPDATE TABLE
SET REQ_STA_CD = (CASE WHEN ENROLL_TYPE = 'R' THEN '6'
WHEN ENROLL_TYPE = 'V' THEN '7' END)
WHERE ENROLL_TYPE = 'R' OR ENROLL_TYPE = 'V'; |
|
|
Back to top |
|
|
rexx77
New User
Joined: 14 Apr 2008 Posts: 78 Location: Mysore
|
|
|
|
AFAIK, there is no single query to perform your requirement. |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
Code: |
UPDATE TABLE A
SET REQ_STA_CD = ( SELECT CASE WHEN ENROLL_TYPE = 'R' THEN '6'
WHEN ENROLL_TYPE = 'V' THEN '7'
END FROM TABLE WHERE COL = A.COL )
|
This is possible only if there is a unique column COL in this table or else the inner query will receive -811. |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
Good one Srihari. |
|
Back to top |
|
|
|