Kod:
DECLARE @KnightsIndex smallint,@NationHuman tinyint,@NationKarus tinyint,@KingKarus varchar(21),@KingHuman varchar(21)
SELECT @KingKarus = strKarusUserID from USER_PERSONAL_RANK where nRank = 1
SELECT @KingHuman = strElmoUserID from USER_PERSONAL_RANK where nRank = 1
SELECT @KnightsIndex = Knights FROM USERDATA where strUserId = @KingKarus
SELECT @KnightsIndex = Knights FROM USERDATA Where strUserId = @KingHuman
SET @NationHuman = 2
SET @NationKarus = 1
UPDATE USERDATA SET Rank = 0 Where Rank = 1
BEGIN
IF EXISTS (SELECT * FROM KING_ELECTION_LIST WHERE strName = @KingKarus)
DELETE FROM KING_ELECTION_LIST WHERE strName = @KingKarus
IF EXISTS (SELECT * FROM KING_CANDIDACY_NOTICE_BOARD WHERE strUserId = @KingKarus)
DELETE FROM KING_CANDIDACY_NOTICE_BOARD WHERE strUserId = @KingKarus
INSERT INTO KING_CANDIDACY_NOTICE_BOARD Values(@KingKarus, @NationKarus, 20, 0)
INSERT INTO [KING_ELECTION_LIST] VALUES(1, @NationKarus, @KnightsIndex, @KingKarus, 0)
UPDATE USERDATA SET Rank = 1 WHERE strUserId = @KingKarus
UPDATE KING_SYSTEM SET strKingName = @KingKarus WHERE byNation = @NationKarus
END
BEGIN
IF EXISTS (SELECT * FROM KING_ELECTION_LIST WHERE strName = @KingHuman)
DELETE FROM KING_ELECTION_LIST WHERE strName = @KingHuman
IF EXISTS (SELECT * FROM KING_CANDIDACY_NOTICE_BOARD WHERE strUserId = @KingHuman)
DELETE FROM KING_CANDIDACY_NOTICE_BOARD WHERE strUserId = @KingHuman
INSERT INTO KING_CANDIDACY_NOTICE_BOARD Values(@KingHuman, @NationHuman, 20, 0)
INSERT INTO [KING_ELECTION_LIST] VALUES(1, @NationHuman, @KnightsIndex, @KingHuman, 0)
UPDATE USERDATA SET Rank = 1 WHERE strUserId = @KingHuman
UPDATE KING_SYSTEM SET strKingName = @KingHuman WHERE byNation = @NationHuman
END