Script that Returns SQL Server’s Version Name

Hi friends, this T-SQL tips is about how you can retrieve the version name a SQL Server instance using the @@VERSION system function in SQL Server.


The T-SQL Script for Retrieving the Version Name

Here’s the script.

As you can see, in order to retrieve the version name for the SQL Server instance we are connected to, we use the @@VERSION system function along with the CHARINDEX string function.

    WHEN CHARINDEX('2019', @@VERSION) > 0 
      THEN 'Microsoft SQL Server 2019'
    WHEN CHARINDEX('2022', @@VERSION) > 0 
      THEN 'Microsoft SQL Server 2022'
    WHEN CHARINDEX('2017', @@VERSION) > 0 
      THEN 'Microsoft SQL Server 2017'
    WHEN CHARINDEX('2016', @@VERSION) > 0 
      THEN 'Microsoft SQL Server 2016'
    WHEN CHARINDEX('2014', @@VERSION) > 0 
      THEN 'Microsoft SQL Server 2014'
    WHEN CHARINDEX('2012', @@VERSION) > 0 
      THEN 'Microsoft SQL Server 2012'
    WHEN CHARINDEX('2008', @@VERSION) > 0 
      THEN 'Microsoft SQL Server 2008'
    ELSE 'Unknown version'
  END AS 'SQL Server Version';



Strengthen your SQL Server Administration Skills – Enroll to our Online Course!

Check our online course on Udemy titled “Essential SQL Server Administration Tips
(special limited-time discount included in link).

Via the course, you will learn essential hands-on SQL Server Administration tips on SQL Server maintenance, security, performance, integration, error handling and more. Many live demonstrations and downloadable resources included!

Essential SQL Server Administration Tips - Online Course with Live Demonstrations and Hands-on Guides
(Lifetime Access/ Live Demos / Downloadable Resources and more!)

Learn More


Related T-SQL Tips on SQLNetHub


Featured Online Courses:


Subscribe to our newsletter and stay up to date!

Subscribe to our YouTube channel (SQLNetHub TV)

Check out our latest software releases!

Check out our eBooks!


Rate this article: 1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5.00 out of 5)


Reference: (

© SQLNetHub