--select top 1 [PK_ControlNo], [PK_ControlNo] + 1 From [dbo].[tbl_Control] Order BY [PK_ControlNo] Desc Declare @New_PK_ControlNo int = 2107 Declare @controlDesc varchar(300) = 'Pickup Alert - Include Skids? Y/N' IF Not Exists (select 1 From [dbo].[tbl_Control] Where [ControlDesc] = @controlDesc) BEGIN print 'control for "' + @controlDesc + '" does not exist' INSERT INTO [dbo].[tbl_Control] ([PK_ControlNo] ,[ControlDesc] ,[ControlValue] ,[Memo] ,[Category] ,[Obsolete]) VALUES (@New_PK_ControlNo ,@controlDesc ,'N' ,'' ,'' ,'') Select @New_PK_ControlNo as NewControlNumber print 'New control flag for "' + @controlDesc + '" -- PK_ControlNo: ' + Cast(@New_PK_ControlNo as Varchar(10)) END ELSE BEGIN Declare @existingControlNo int = 0; select top(1) @existingControlNo = [PK_ControlNo] From [dbo].[tbl_Control] Where [ControlDesc] = @controlDesc print 'NOTE: control for "' + @controlDesc + '" already exists! PK_ControlNo: ' + Cast(@existingControlNo as Varchar(10)) END