I know to query the current Compatibility Level of a database with
declare @dbname sysname
select @dbname = db_name(0)
exec sp_dbcmptlevel @dbname
But this seems to return its result via print and I have found no way to assign the value to a variable and use it to control if ... else ... constructs to execute different code depending on current setting.