Check the version of SQL Server for a database using TSQL

SELECT
@@SERVERNAME AS ServerName,
CASE
 WHEN LEFT(CAST(serverproperty('productversion') as char), 1) = 8 THEN '2000'
 WHEN LEFT(CAST(serverproperty('productversion') as char), 1) = 9 THEN '2005'
 WHEN LEFT(CAST(serverproperty('productversion') as char), 2) = 10 THEN '2008'
 WHEN LEFT(CAST(serverproperty('productversion') as char), 2) = 11 THEN '2012'
 WHEN LEFT(CAST(serverproperty('productversion') as char), 2) = 12 THEN '2014'
END AS MajorVersion,
SERVERPROPERTY ('productlevel') AS MinorVersion,
SERVERPROPERTY('productversion') AS FullVersion,
SERVERPROPERTY ('edition') AS Edition