CREATE PROCEDURE [dbo].[up_add_friend] ( @character_id [uniqueidentifier], @friend_name nvarchar(16) ) as set nocount on declare @friend_id [uniqueidentifier]; declare @friend_class int , @Block_Type tinyint , @friend_level int; set @friend_id = NULL select TOP 1 @friend_id = [character_id] , @friend_class = [class] , @friend_level = [level] , @Block_Type = Block_Type from dbo.CharacterTable WITH(READUNCOMMITTED) WHERE [Name] = @friend_name IF( @friend_id IS NOT NULL AND @Block_Type = 0 ) BEGIN if NOT EXISTS ( select TOP 1 character_id from dbo.FriendTableEx WITH(READUNCOMMITTED) where character_id = @character_id and friend_id = @friend_id ) BEGIN insert into dbo.FriendTableEx values( @character_id, @friend_id, @friend_name, @friend_class, 0, '', GetDate() ); IF EXISTS ( SELECT TOP 1 [character_id] FROM dbo.FriendTableEx WITH(READUNCOMMITTED) WHERE [Name] = @friend_name ) BEGIN SELECT @friend_id [character_id], @friend_class [class], @friend_level [level] RETURN; END END END SELECT @friend_id , @friend_class , @friend_level RETURN;