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 ...
This is only a preview. Your comment has not yet been posted.
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.
Posted by: |