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 Row By Row

Author  Topic 

asif372
Posting Yak Master

100 Posts

Posted - 2011-02-26 : 13:45:45
Basically I Am Developing Attendance System data from Attendance Machine I Get In First In Second Out Third In Fourth Out condition just like this
(UserID) (CheckTime) (Checktype(In or Out))
(1) (10/18/2010 9:39:08 AM) (I)
(1) (10/18/2010 6:12:46 PM) (o)
(1) (10/18/2010 6:12:47 PM) (I)
(1) (10/19/2010 8:24:13 AM) (O)
(1) (10/19/2010 8:24:13 PM) (I)

i want to developed a Delete Trigger when any Data Deleted it should fire and update All Checktype > deleted checktime where Userid=Deleted

I have Developed a Trigger But Not Working as Per My Need

Create Trigger [dbo].[DeleteCheck]
On [dbo].[CHECKINOUT]
After Delete
AS
BEGIN
Declare @CtypeULess varchar(1);
Declare @Ctype varchar(1);
Declare @CUtype varchar(1);
DECLARE @Date Datetime;
DECLARE @ID int;
SET @ID =(select USERID from Deleted);
SET @CtypeULess= (select CHECKTYPE from Deleted);
SET @Date = (Select CheckTime from Deleted);
SET @Ctype =(SELECT Top 1 CheckTypeUpdated FROM CHECKINOUT where USERID = @Id and ORDER BY CHECKTIME DESC);
if(@Ctype='I')
SET @CUtype='O'
Else if (@Ctype='O')
SET @CUtype='I'
Else
SET @CUtype='I'
Insert Into CheckInOutDeleted Values(@ID,@Date,@CUtype,'a')
update CheckInOut Set CheckTypeUpdated=@CUtype Where USERID=@ID and CHECKTIME >(@ID)
End

This Check Condition One Time and Then Update All Records I Want Him To Check Condition Row By Row And Then Update CheckType

any ideas????
Thanks In Advance

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-02-26 : 15:03:56
Duplicate of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=157449
Go to Top of Page
   

- Advertisement -