IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Using case statement in update query in DB2


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ankita.maheswari11

New User


Joined: 20 Aug 2011
Posts: 10
Location: India

PostPosted: Tue Sep 20, 2011 12:33 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Sep 20, 2011 2:50 pm
Reply with quote

Quote:
I a getting a SQL error.


i am getting a stomach-ache from laughing so loud.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Tue Sep 20, 2011 2:59 pm
Reply with quote

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
View user's profile Send private message
Dsingh29

Active User


Joined: 16 Dec 2008
Posts: 132
Location: IBM

PostPosted: Tue Sep 20, 2011 3:02 pm
Reply with quote

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
View user's profile Send private message
ankita.maheswari11

New User


Joined: 20 Aug 2011
Posts: 10
Location: India

PostPosted: Tue Sep 20, 2011 3:38 pm
Reply with quote

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
View user's profile Send private message
ankita.maheswari11

New User


Joined: 20 Aug 2011
Posts: 10
Location: India

PostPosted: Tue Sep 20, 2011 4:14 pm
Reply with quote

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
View user's profile Send private message
Dsingh29

Active User


Joined: 16 Dec 2008
Posts: 132
Location: IBM

PostPosted: Tue Sep 20, 2011 4:18 pm
Reply with quote

Good to hear that icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
Search our Forums:

Back to Top