Follow sqlserver-dba.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

SQLServer-DBA.com Links

Dba_db2_button

dba-ninja.com

SQL Server DBA Jobs

How to use parsename with SERVERPROPERTY('productversion')

14 September,2018 by Tom Collins

Question: I'd like to use SERVERPROPERTY('productversion')  for purposes of reporting on current sql server level. I'm using the  SERVERPROPERTY('productversion') funcion   , but am struggling with how to split the parts of the details , to make it easier for reporting.

For example : 13.0.5081.1      , I'd like to split as   

Major = 13 

Minor = 0

Build =  5081

Revision =  1

Answer:  The PARSENAME function can be used to split the SERVERPROPERTY('productversion') and avoid using various string functions.

PARSENAME is commonly used to split object names into there constituent parts. Here is an example:

 

select parsename('master.dbo.sysdatabases',1)
  select parsename('master.dbo.sysdatabases',2)
  select parsename('master.dbo.sysdatabases',3)

This would return:

sysdatabases

dbo

master

If we apply the same concept to SERVERPROPERTY('productversion'), the example would look like:

 

select 
  SERVERPROPERTY('productversion') as product_version,
  parsename(convert(varchar,serverproperty ('productversion')),4) As major,
  parsename(convert(varchar,serverproperty ('productversion')),3) As minor,
  parsename(convert(varchar,serverproperty ('productversion')),2) As build,
  parsename(convert(varchar,serverproperty ('productversion')),1) As revision

 

product_version     major     minor     build     revision
13.0.5081.1     13     0     5081     1

 

Read More on SERVERPROPERTY and SQL Server Versions

Difference between @@servername and SERVERPROPERTY(ServerName)

Get cumulative update number for SQL Server Version (SQL Server ...

 

 


Author: Tom Collins (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on How to use parsename with SERVERPROPERTY('productversion')


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer