DECLARE @MainUserName NVARCHAR(50)
DECLARE @UserNameForeDelete NVARCHAR(50)
SET @MainUserName = N'ali'
SET @UserNameForeDelete = N'sonam'
IF EXISTS(SELECT     dbo.tblContactLists.MainUserID, tblUsers_1.IUserName AS AdminUser, dbo.tblContactLists.UserInContactListID, dbo.tblUsers.IUserName AS UserMember
FROM         dbo.tblContactLists INNER JOIN
                      dbo.tblUsers ON dbo.tblContactLists.UserInContactListID = dbo.tblUsers.IUserID INNER JOIN
                      dbo.tblUsers AS tblUsers_1 ON dbo.tblContactLists.MainUserID = tblUsers_1.IUserID
WHERE     (tblUsers_1.IUserName = @MainUserName) AND (dbo.tblUsers.IUserName = @UserNameForeDelete))
BEGIN
	DELETE FROM dbo.tblContactLists WHERE ContactListID = (SELECT   dbo.tblContactLists.ContactListID
		FROM         dbo.tblContactLists INNER JOIN
							  dbo.tblUsers ON dbo.tblContactLists.UserInContactListID = dbo.tblUsers.IUserID INNER JOIN
							  dbo.tblUsers AS tblUsers_1 ON dbo.tblContactLists.MainUserID = tblUsers_1.IUserID
		WHERE     (tblUsers_1.IUserName = @MainUserName) AND (dbo.tblUsers.IUserName = @UserNameForeDelete))
END

