Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Query Needed

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Query Needed
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: 1452
Location: Chicago, IL

PostPosted: Wed Dec 28, 2005 10:30 am    Post subject: Re: Query Needed
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    Post subject:
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: 680
Location: NJ

PostPosted: Wed Dec 28, 2005 11:34 am    Post subject: Query
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: 1452
Location: Chicago, IL

PostPosted: Wed Dec 28, 2005 11:34 am    Post subject: Re: Query Needed
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    Post subject:
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    Post subject: Re: Query Needed
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    Post subject: see this
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Join in SQL Query vickey_dw DB2 1 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us