There isn't a clean way that I know of. You could try set them all incrementally then see what the final value is. That will return the current maximum:
DECLARE @SQL NVARCHAR(MAX)
SET @SQL = 'ALTER DATABASE '+DB_NAME()+' SET COMPATIBILITY_LEVEL = 130'; EXEC (@SQL)
SET @SQL = 'ALTER DATABASE '+DB_NAME()+' SET COMPATIBILITY_LEVEL = 140'; EXEC (@SQL)
SET @SQL = 'ALTER DATABASE '+DB_NAME()+' SET COMPATIBILITY_LEVEL = 150'; EXEC (@SQL)
SET @SQL = 'ALTER DATABASE '+DB_NAME()+' SET COMPATIBILITY_LEVEL = 160'; EXEC (@SQL)
SET @SQL = 'ALTER DATABASE '+DB_NAME()+' SET COMPATIBILITY_LEVEL = 170'; EXEC (@SQL)
SELECT compatibility_level FROM sys.databases WHERE name = DB_NAME()
-- currently returns compatibility_level=150
Obviously you don't want to do this on an active application database as changing the levels could have consequences for the application users.
The test above uses ad-hoc SQL because otherwise the later versions fail syntax check without it even trying the rest, and you have to hard-code the database name. In SSMS or similar you could get around the first issue by breaking the batch into multiple:
ALTER DATABASE test_clvl SET COMPATIBILITY_LEVEL = 130
GO
ALTER DATABASE test_clvl SET COMPATIBILITY_LEVEL = 140
GO
ALTER DATABASE test_clvl SET COMPATIBILITY_LEVEL = 150
GO
ALTER DATABASE test_clvl SET COMPATIBILITY_LEVEL = 160
GO
ALTER DATABASE test_clvl SET COMPATIBILITY_LEVEL = 170
GO
SELECT compatibility_level FROM sys.databases WHERE name = DB_NAME()
If you can use outside tools, then script up a database create, then find the level from master.sys.databases, then drop the test DB, using powershell or similar.
In any case you'll need to ignore the error responses to the later versions. Perhaps TRY
/CATCH
can make this cleaner, but I'll leave you to play with that.