declare @UID as int
declare @Count as int
declare @CharNum as int

declare cursor1 cursor for

Select UID From RYL_Users.dbo.usertbl

open cursor1 

FETCH NEXT FROM cursor1 INTO @UID

WHILE @@FETCH_STATUS = 0

BEGIN

Set @Count = (Select Count(*) From TblUnifiedItemStore1 Where UID = @UID)

if @Count > 1

Begin

Set @CharNum = (Select Count(*) From UserInfo Where UID = @UID And OldServerGroupID = 24 And (Char1 <> 0 or Char2 <> 0 or Char3 <> 0 or Char4 <> 0 or Char5 <> 0))

if @CharNum > 0

Begin

Update UserInfo Set OldServerGroupID = 6 Where UID = @UID And OldServerGroupID = 24

Update TblUnifiedCharList Set OldServerGroupID = 6 Where UID = @UID And OldServerGroupID = 24

Update TblUnifiedItemStore1 Set OldServerGroupID = 6 Where UID = @UID And OldServerGroupID = 24

Update TblUnifiedItemStore2 Set OldServerGroupID = 6 Where UID = @UID And OldServerGroupID = 24

End

End

FETCH NEXT FROM cursor1 INTO @UID

End

CLOSE cursor1

DEALLOCATE cursor1