How to determine the academic year of an Aeries database in SQL.
SELECT CAST(20-FLOOR(CAST(SUBSTRING(DB_NAME(),4,2) AS INT)/80) AS VARCHAR(2)) + CAST(SUBSTRING(DB_NAME(),4,2) AS VARCHAR(2))
To get the full YYYY-YYYY string you can use the following.
DECLARE @Y1 as int = CAST(20-FLOOR(CAST(SUBSTRING(DB_NAME(),4,2) AS INT)/80) AS VARCHAR(2)) + CAST(SUBSTRING(DB_NAME(),4,2) AS VARCHAR(2)) SELECT CAST(@Y1 AS VARCHAR(4)) + '-' + CAST(@Y1 +1 AS VARCHAR(4))