DECLARE @VERSION AS VARCHAR(30),
		@SCRIPT AS VARCHAR(100)

SELECT @VERSION = CONVERT(VARCHAR(30), SERVERPROPERTY('productversion'))

-- 13.x versiones compatibles con 130
IF SUBSTRING(@VERSION, 1, 2) >= 13 AND NOT EXISTS(SELECT name FROM sys.databases WHERE name = DB_NAME(db_id()) AND compatibility_level = 130)
BEGIN 
	SET @SCRIPT = CONCAT('ALTER DATABASE [', DB_NAME(db_id()), '] SET COMPATIBILITY_LEVEL = 130')
	EXEC(@SCRIPT)
END