How to get all characters on the account has the same amount of kill?
Declare @CharID varchar(30) = (Select top 1 CharID from PS_GameData.dbo.chars where CharName='123') Declare @UserID varchar(12) =(select top 1 UserID from PS_GameData.dbo.chars where CharID =@CharID) Declare @Slot1 int =(Select top 1 k1 From PS_GameData.dbo.chars where UserID =@UserID and slot ='0' and del ='0') Declare @Slot2 int =(Select top 1 k1 From PS_GameData.dbo.chars where UserID =@UserID and slot ='1' and del ='0') Declare @Slot3 int =(Select top 1 k1 From PS_GameData.dbo.chars where UserID =@UserID and slot ='2' and del ='0') Declare @Slot4 int =(Select top 1 k1 From PS_GameData.dbo.chars where UserID =@UserID and slot ='3' and del ='0') Declare @Slot5 int =(Select top 1 k1 From PS_GameData.dbo.chars where UserID =@UserID and slot ='4' and del ='0') Declare @S1 int =(Select top 1 k2 From PS_GameData.dbo.chars where UserID =@UserID and slot ='0' and del ='0') Declare @S2 int =(Select top 1 k2 From PS_GameData.dbo.chars where UserID =@UserID and slot ='1' and del ='0') Declare @S3 int =(Select top 1 k2 From PS_GameData.dbo.chars where UserID =@UserID and slot ='2' and del ='0') Declare @S4 int =(Select top 1 k2 From PS_GameData.dbo.chars where UserID =@UserID and slot ='3' and del ='0') Declare @S5 int =(Select top 1 k2 From PS_GameData.dbo.chars where UserID =@UserID and slot ='4' and del ='0' ) Declare @Toon1 int =(Select top 1 CharID From PS_GameData.dbo.chars where UserID =@UserID and slot ='0' and del ='0') Declare @Toon2 int =(Select top 1 CharID From PS_GameData.dbo.chars where UserID =@UserID and slot ='1' and del ='0') Declare @Toon3 int =(Select top 1 CharID From PS_GameData.dbo.chars where UserID =@UserID and slot ='2' and del ='0') Declare @Toon4 int =(Select top 1 CharID From PS_GameData.dbo.chars where UserID =@UserID and slot ='3' and del ='0') Declare @Toon5 int =(Select top 1 CharID From PS_GameData.dbo.chars where UserID =@UserID and slot ='4' and del ='0') update PS_GameData.dbo.chars Set K1 = @Slot1+@Slot2+@Slot3+@Slot4+@Slot5 Where CharID=@CharID PRINT 'Update 1' update PS_GameData.dbo.chars Set K2 = @S1+@S2+@S3+@S4+@S5 Where CharID=@CharID PRINT 'Update 2' update PS_GameData.dbo.chars Set K1 = '0' Where CharID=@Toon1 PRINT 'Update 3' update PS_GameData.dbo.chars Set K1 = '0' Where CharID=@Toon2 PRINT 'Update 4' update PS_GameData.dbo.chars Set K1 = '0' Where CharID=@Toon3 PRINT 'Update 5' update PS_GameData.dbo.chars Set K1 = '0' Where CharID=@Toon4 PRINT 'Update 6' update PS_GameData.dbo.chars Set K1 = '0' Where CharID=@Toon5 PRINT 'Update 7' update PS_GameData.dbo.chars Set K2 = '0' Where CharID=@Toon1 PRINT 'Update 8' update PS_GameData.dbo.chars Set K2 = '0' Where CharID=@Toon2 PRINT 'Update 9' update PS_GameData.dbo.chars Set K2 = '0' Where CharID=@Toon3 PRINT 'Update 10' update PS_GameData.dbo.chars Set K2 = '0' Where CharID=@Toon4 PRINT 'Update 11' update PS_GameData.dbo.chars Set K2 = '0' Where CharID=@Toon5 PRINT 'Update 12' update PS_GameData.dbo.chars Set K1 = @Slot1+@Slot2+@Slot3+@Slot4+@Slot5 Where CharID=@CharID PRINT 'Update 1a' update PS_GameData.dbo.chars Set K2 = @S1+@S2+@S3+@S4+@S5 Where CharID=@CharID PRINT 'Update 2a'
Msg 515, Level 16, State 2, Line 22 Cannot insert the value NULL into column 'K1', table 'PS_GameData.dbo.Chars'; column does not allow nulls. UPDATE fails. The statement has been terminated. Update 1 Msg 515, Level 16, State 2, Line 27 Cannot insert the value NULL into column 'K2', table 'PS_GameData.dbo.Chars'; column does not allow nulls. UPDATE fails. The statement has been terminated. Update 2