SQL Server – Transact SQL – Query SQL Server for Version Info

Background

Still amazes me that it is difficult to translate SQL Server Version Numbers to the Marketing Name.

Here is one way.

Code

There is nothing special here, but wanted to keep it and come back and update as time goes on.

Query Code



; with cteProductVersion
as
(
	select
			    [productVersion] = serverproperty('ProductVersion')

			 ,  [productVersionMajor] 
					= parseName
					  (
					      cast(serverproperty('ProductVersion') as sysname)
						, 4
					 ) 

			 ,  [productVersionMinor] 
					= parseName
					  (
					      cast(serverproperty('ProductVersion') as sysname)
						, 3
					 ) 

			 ,  [productVersionMajorAndMinor] 
					= cast
						(
							parseName
						    (
								cast(serverproperty('ProductVersion') as sysname)
								, 4
							) 
							+ '.'
							+ parseName
							(
								cast(serverproperty('ProductVersion') as sysname)
								, 3
							) 
							as decimal(6, 2)
						)

)
select


		  [marketing]
			= case ctePV.[productVersionMajorAndMinor] 
						when 12 then '2014'
						when 11 then '2012'
						when 10.5 then '2008-R2'
						when 10 then '2008'
						when 9 then '2005'
						when 8 then '2000'
						else ''
				end 		
 
        , [edition] 
			= cast(serverproperty('edition') as sysname)

        , [engineedition] 
			= cast(serverproperty('engineedition') as sysname)

        , [productLevel] 
			= cast(serverproperty('productLevel') as sysname)

        , [ProductUpdateLevel]
			 = cast(serverproperty('productUpdateLevel') as sysname)

        , [productBuild] 
			= cast(serverproperty('productBuild') as int)

        , [productBuildType]
			 = cast(serverproperty('ProductBuildType') as sysname)

        , [ProductVersion]
            = cast(serverproperty('ProductVersion') as sysname)

        , [@@version] = @@version 

        , [ProductMajorVersion]
            = cast(serverproperty('ProductMajorVersion') as int)

        , [ProductMinorVersion]
            = cast(serverproperty('ProductMinorVersion') as int)

        , [IsXTPSupported]
            = cast(serverproperty('IsXTPSupported') as bit)

        , [InMemory]
            = case isNull(cast(serverproperty('IsXTPSupported') as bit), 0)
                    when 0 then 'No'
                    else 'Yes'
              end

from cteProductVersion ctePV

Output

v2008-R2

sqlserverengine_v2008r2

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s