CREATE PROCEDURE dbo.SQLServerVersion2016OrNewer @AVersion BIT OUTPUT AS

DECLARE @ver VARCHAR(MAX)
DECLARE @SP VARCHAR(MAX)

SELECT @ver = CAST(SERVERPROPERTY('productversion') AS VARCHAR(100))
SELECT @sp = CAST(SERVERPROPERTY ('ProductLevel') AS VARCHAR(5))

IF CAST(SUBSTRING(@ver, 0, CHARINDEX('.', @ver)) AS INT) > 13 -- SQL Server 2016 SP 1 or newer
  OR (CAST(SUBSTRING(@ver, 0, CHARINDEX('.', @ver)) AS INT) = 13 AND dbo.IsReallyNumeric (SUBSTRING(@SP, 3, 1)) = 1 AND CAST(SUBSTRING(@SP, 3, 1) AS INT) >= 1) -- SQL 2016 SP1 or newer sp
  SET @AVersion = 1
ELSE
  SET @AVersion = 0
  