4
votes

How do I get only the SQL Server release version?

select @@version

retrieves the full information, in my case :

Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (X64) Apr 22 2011 19:23:43 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1)

I need only Microsoft SQL Server 2008 R2.

Suggestions?

3

3 Answers

4
votes

How about:

SELECT 
    SERVERPROPERTY('Edition'),
    SERVERPROPERTY('ProductVersion')

I get this output:

Developer Edition (64-bit)  10.50.2500.0

Based on the ProductVersion , you could do a "translation" to a human-readable SQL Server version name...

11.xx   --> SQL Server 2012
10.50.  --> SQL Server 2008 R2
10.00.  --> SQL Server 2008
09.xx   --> SQL Server 2005

etc.

2
votes

Try using SERVERPROPERTY

For example

select SERVERPROPERTY('ProductVersion')

returns 10.50.2500.0 for SQL Server 2008 R2.

There are many other values you can retrieve using SERVERPROPERTY.

1
votes
SELECT SUBSTRING(@@VERSION,0,CHARINDEX('-',@@VERSION,0))

Gives (for me)

`Microsoft SQL Server 2012`