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

Query Needed


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

New User


Joined: 15 Aug 2005
Posts: 62

PostPosted: Wed Dec 28, 2005 10:27 am
Reply with quote

Hi All ,

My requirement is like this

Name salary paid
bbbb 10000 y
cccc 12000 y
dddd 13000 n
eeee 14000 y
ffffff 15000 n

This is a db2 table , here i want to change the paid flag from y to n and n to y in a single DB2 Query

thanks in advance
Balaji
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Wed Dec 28, 2005 10:30 am
Reply with quote

And what is the primery key for the table ?

Regards,

Priyesh.
Back to top
View user's profile Send private message
sbalajibe

New User


Joined: 15 Aug 2005
Posts: 62

PostPosted: Wed Dec 28, 2005 10:34 am
Reply with quote

there a employee id column is foreign key in this table
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 677
Location: NJ

PostPosted: Wed Dec 28, 2005 11:34 am
Reply with quote

Hi balaji,
V can use a temperory flag in order to change y--n and n--y. but it will take three queries. as like swapping v can do ie., y--a and n--y finally a--n. like that.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Wed Dec 28, 2005 11:34 am
Reply with quote

I have yet to run a query for that...meanwhile, Here is discussed exactly what you requested for....Dont know the results...

http://ibmmainframes.com/viewtopic.php?t=7260

Regards,

Priyesh.
Back to top
View user's profile Send private message
nrsmca

New User


Joined: 25 May 2005
Posts: 14

PostPosted: Mon Jan 09, 2006 7:43 pm
Reply with quote

Update empsaltable a
set a.flag =
(Select (case
when (b.flag = 'y') then (n)
else (y)
end) b.flag
from empsaltable b where a.name = b.name);

Please Correct me...!
Back to top
View user's profile Send private message
umed

New User


Joined: 13 May 2005
Posts: 38

PostPosted: Mon Jan 09, 2006 9:10 pm
Reply with quote

Hi,
u can use following query

update t1_emp a
set sex=(select distinct(sex) from t1_emp b where b.sex <> a.sex)

Let me know if u have any concerns

Regards,
Umed
Back to top
View user's profile Send private message
ragshere

New User


Joined: 20 Dec 2004
Posts: 70

PostPosted: Tue Jan 10, 2006 3:01 pm
Reply with quote

update EMP
set paid =
( case select
when paid='Y' then 'N'
when paid='N' then 'Y'
end
)


Bye
Rags
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 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
No new posts Mainframe Programmer with CICS Skill... Mainframe Jobs 0
Search our Forums:

Back to Top