View previous topic :: View next topic
|
Author |
Message |
ankita.maheswari11
New User
Joined: 20 Aug 2011 Posts: 10 Location: India
|
|
|
|
Hi,
I have to create a update query in which i have to set a = '2' if b = '23202' and '1' if b = 'V1368', also i have to check for conditions where end_dt = '9999-12-31' and eff_dt = '2006-10-01'.
For this i want to use a case in update query, i have created a query but it is not working, please find the query below:
UPDATE IMSX01.BEV04001_DIAGNOSIS
SET a = CASE
WHEN b = '23202' THEN a = '2'
WHEN b = 'V1368' THEN a = '1'
END
WHERE END_DT = '9999-12-31'
AND EFF_DT = '2006-10-01';
Can some one please help me this? I a getting a SQL error. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
I a getting a SQL error.
|
i am getting a stomach-ache from laughing so loud. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
If you provide information regarding the SQL error )such as the message and message number and what the manual says about the message) maybe Dick will be able to stop laughing and start to help you. |
|
Back to top |
|
|
Dsingh29
Active User
Joined: 16 Dec 2008 Posts: 132 Location: IBM
|
|
|
|
Quote: |
UPDATE IMSX01.BEV04001_DIAGNOSIS
SET a = CASE
WHEN b = '23202' THEN a = '2'
WHEN b = 'V1368' THEN a = '1'
END
WHERE END_DT = '9999-12-31'
AND EFF_DT = '2006-10-01'; |
try this
Code: |
UPDATE IMSX01.BEV04001_DIAGNOSIS
SET a = CASE
WHEN b = '23202' and END_DT = '9999-12-31' and EFF_DT = '2006-10-01' THEN '2'
WHEN b = 'V1368' and END_DT = '9999-12-31' and EFF_DT = '2006-10-01' THEN '1'
END |
|
|
Back to top |
|
|
ankita.maheswari11
New User
Joined: 20 Aug 2011 Posts: 10 Location: India
|
|
|
|
Tried below:
UPDATE IMSX01.BEV04001_DIAGNOSIS
SET a =
CASE
WHEN b = 'V1368' AND END_DT = '9999-12-31'
AND EFF_DT = '2006-10-01' THEN 1
WHEN b = '23202' AND END_DT = '9999-12-31'
AND EFF_DT = '2006-10-01' THEN 2
END
Getting below error:
"Column cannot contain a NULL value." Their is no number coming with this error message... |
|
Back to top |
|
|
ankita.maheswari11
New User
Joined: 20 Aug 2011 Posts: 10 Location: India
|
|
|
|
Thanks for the help guys.
It is done, the problem was i was not using else part of case. but now i am using it and query is running fine. |
|
Back to top |
|
|
Dsingh29
Active User
Joined: 16 Dec 2008 Posts: 132 Location: IBM
|
|
|
|
Good to hear that |
|
Back to top |
|
|
|