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.
SELECT CASE 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!
Related T-SQL Tips on SQLNetHub
- Getting the Paths for All Database Files in a SQL Server Instance
- Executing T-SQL Statements Against All Databases
- Listing all Tables of a Linked Server’s Database
- Inserting Leading Characters to a String
- Retrieving Security-Related Info for SQL Server Logins
- Getting all the Records from all Tables in all User Databases
- …more
Featured Online Courses:
- SQL Server 2022: What’s New – New and Enhanced Features
- Introduction to Azure Database for MySQL
- Working with Python on Windows and SQL Server Databases
- Boost SQL Server Database Performance with In-Memory OLTP
- Introduction to Azure SQL Database for Beginners
- Essential SQL Server Administration Tips
- SQL Server Fundamentals – SQL Database for Beginners
- Essential SQL Server Development Tips for SQL Developers
- Introduction to Computer Programming for Beginners
- .NET Programming for Beginners – Windows Forms with C#
- SQL Server 2019: What’s New – New and Enhanced Features
- Entity Framework: Getting Started – Complete Beginners Guide
- A Guide on How to Start and Monetize a Successful Blog
- Data Management for Beginners – Main Principles
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:
Reference: SQLNetHub.com (https://www.sqlnethub.com)
© SQLNetHub
Artemakis Artemiou, a distinguished Senior Database and Software Architect, brings over 20 years of expertise to the IT industry. A Certified Database, Cloud, and AI professional, he earned the Microsoft Data Platform MVP title for nine consecutive years (2009-2018). As the founder of SQLNetHub and GnoelixiAI Hub, Artemakis is dedicated to sharing his knowledge and democratizing education on various fields such as: Databases, Cloud, AI, and Software Development. His commitment to simplicity and knowledge sharing defines his impactful presence in the tech community.