Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to write below query ?

Author  Topic 

usafelix
Posting Yak Master

165 Posts

Posted - 2015-01-30 : 02:52:01
Dear Sir,
i have two field column and want to write this query. how to do ?

select temp_staff, per_staff,
if temp_Staff<>'' and per_staff=''
then
copy temp_staff to per_staff
copy space to temp_staff
end
amount,
total
from test

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-01-30 : 07:21:05
Look up the CASE expression
Go to Top of Page

usafelix
Posting Yak Master

165 Posts

Posted - 2015-02-02 : 05:09:49
pls direct edit my query . help
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-02-02 : 07:04:57
Try it on your own first using a case expression
Go to Top of Page

pradeepbliss
Starting Member

28 Posts

Posted - 2015-02-05 : 03:57:50
quote:
Originally posted by usafelix

Dear Sir,
i have two field column and want to write this query. how to do ?

select temp_staff, per_staff,
if temp_Staff<>'' and per_staff=''
then
copy temp_staff to per_staff
copy space to temp_staff
end
amount,
total
from test




Simple Update query without using case
update s set s.temp_staff=s.per_staff,s.per_staff=s.temp_staff from test s where temp_Staff <>'' and per_staff=''
update s set s.per_staff=s.temp_staff,s.temp_staff=s.per_staff from test s where temp_Staff = '' and per_staff <>''
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-02-05 : 09:49:31
@pradeepbliss

The OP never said he wanted to updated the data!
Go to Top of Page
   

- Advertisement -