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
 Update Using Condition

Author  Topic 

asif372
Posting Yak Master

100 Posts

Posted - 2011-03-17 : 14:42:09
I Have A Table naming CheckInOut like this

(UserID) (CheckTime) (Checktype)
(1) (10/18/2010 2:39:08 PM) (I)
(1) (10/18/2010 9:12:46 PM) (o)
(1) (10/19/2010 8:56:21 AM) (I)
(1) (10/20/2010 8:50:21 AM) (I)
(1) (10/20/2010 8:24:13 PM) (O)

i want to update CheckType using these condition update table where chectype='I' Set CheckType='O' and where checktype='O' Set CheckType='I' i am using this query but first one update checktype where CheckType='O' to 'I' and then update all to 'O'
i want to update I to O and O to I
any Ideas?????

update CheckInOut Set CheckType='I' where CheckType='O'
update CheckInOut Set CheckType='O' where CheckType='I'

Thanks In Advance

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-03-17 : 14:50:33
update CheckInOut
Set CheckType=CASE WHEN CheckType='O' THEN 'I'
WHEN CheckType='I' THEN 'O'
ELSE CheckType END
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-03-17 : 14:51:33
tell us how you relate a checked in time to a checked out time. And what if one of those is missing. And is it with ing the same day? Cross over days?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

asif372
Posting Yak Master

100 Posts

Posted - 2011-03-17 : 15:05:46
Thanks A Lot Its Working Fine
Go to Top of Page
   

- Advertisement -