Determine Which Version of SQL You Are Running

The following are two T-SQL methods that determine which version of SQL you are running. The first one is very short, using the @@VERSION?variable, whereas the longer method makes use of SERVERPROPERTY:

SELECT @@VERSIONSELECT  CASE      WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '8%' THEN 'SQL2000'     WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '9%' THEN 'SQL2005'     WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '10.0%' THEN 'SQL2008'     WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '10.5%' THEN 'SQL2008 R2'     WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '11%' THEN 'SQL2012'     WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '12%' THEN 'SQL2014'     WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '13%' THEN 'SQL2016'          WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '14%' THEN 'SQL2017'      ELSE 'unknown'  END AS MajorVersion,  SERVERPROPERTY('ProductVersion') [RealMajorVersion],  SERVERPROPERTY('ProductLevel') AS ProductLevel,  SERVERPROPERTY('Edition') AS Edition
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: