DECLARE @UserID int SET @UserID = ( SELECT UserID FROM ircUsers WHERE UserName = @Username ) if @UserID = NULL begin INSERT INTO ircUsers VALUES ( @Username ) SET @UserID = @@IDENTITY end