Interview Question of the Week #028 – T-SQL Script to Detect SQL Server Version and Property

I asked nearly twenty interview candidates how to find the SQL Server version with T-SQL. Only five could write the query, even with the internet available. The answer can start with three SERVERPROPERTY calls. The interesting follow-up is whether the candidate knows which server the result describes.

Nested brass sleeves reveal successive engine layers

What is the SQL Server version and edition?

Run the query on the connection you want to inspect. This keeps the original answer’s product version, product level, and edition, and adds the connected server name and engine category.

SELECT SERVERPROPERTY('ServerName') AS ConnectedServer,
       SERVERPROPERTY('ProductVersion') AS ProductVersion,
       SERVERPROPERTY('ProductLevel') AS ProductLevel,
       SERVERPROPERTY('Edition') AS Edition,
       SERVERPROPERTY('EngineEdition') AS EngineEdition;

ProductVersion is the complete engine build. ProductLevel can describe a release level such as RTM; it alone does not establish the latest cumulative update. Edition describes the installed edition. These are properties of the connected database engine, not the SSMS application on your desk.

Translate a major version carefully

When a report needs a familiar release label, check the engine category before mapping a major version to a boxed SQL Server release. The following query was run on the SQL Server 2025 test instance; its result is shown directly below it.

DECLARE @Major int = TRY_CONVERT(int, SERVERPROPERTY('ProductMajorVersion'));
DECLARE @Engine int = TRY_CONVERT(int, SERVERPROPERTY('EngineEdition'));

SELECT @Major AS MajorVersion, @Engine AS EngineCategory,
       CASE WHEN @Engine = 5 THEN N'Azure SQL Database'
            WHEN @Engine = 8 THEN N'Azure SQL Managed Instance'
            WHEN @Major = 17 THEN N'SQL Server 2025'
            WHEN @Major = 16 THEN N'SQL Server 2022'
            WHEN @Major = 15 THEN N'SQL Server 2019'
            ELSE N'Check the documented release mapping'
       END AS ReleaseLabel;
SSMS result: major version 17, engine category 3, SQL Server 2025
Actual SSMS result from the SQL Server 2025 test instance for the query above.

The label is a convenience, not a permanent patch-status check. Compare the full build with current release information when servicing level matters. Database compatibility level is another separate setting; it does not change the engine’s product version. My interview answer remains short: query the server you connected to, then interpret each property for the question you were actually asked.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

Previous Post
PostgreSQL Local Variable: DECLARE in a plpgsql Function
Next Post
SQL SERVER – How to Change Server Name?

Related Posts

No results found.

8 Comments. Leave new

  • Dear Sir
    SELECT @@Version gives similar results .. whats the difference between these two ?

    Reply
  • Everton Custodio
    July 12, 2015 8:18 am

    Is the instruction @@VERSION a valid answer? Like in SELECT @@VERSION.

    Reply
    • Everton – As madhivanan said, you need to parse results if you want to use in subsequent queries.

      Reply
  • As an interviewer I find questions like these not as useful as finding out if the candidate can use available tools to answer the question. Tools including Google. What is the point of hiring someone that can wow you in an interview then in real life can’t solve simple real world problems.

    Reply
  • What’s wrong with Select @@Version?

    Reply
    • Robb – Nothing wrong with @@version. If you want to use the exact build into your script to take any action then you need to parse the output of @@version and find required info like edition etc.

      Reply
  • Mubashar Anwer
    August 3, 2015 7:00 pm

    i enjoying learning Through Your usefull Blogs . Sir You Doing A great Job

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.