Page 1 of 1

How to parse a version number

Posted: Mon Jan 11, 2016 6:06 am
by Dame1701
Hi Guys,

I'm currently working on a script that will enumerate SQL versions installed onm a machine to see if the version is the same or greater than the minimum version required to run our product. To achieve this, i have been mopdifying the Enumerate SQL Instances script.

I want to parse a variable I have created, MS_SQL_VERSION which retrieves the value of an installed SQL instance. The value might be for example 12.1.4213.0. I want to use parse string to grab the major version number which would be 12 in this case. I've been trying to find some information on how I would do this by specifying a pattern. I can't do this by trimming the string at a particular position since the major version number might be shorter than a two digit number for example 8.

If I was doing this in C#, I'd do something like take all the characters up to the first full stop. Can someone provide me with either some documentation on how to set up a parse string pattern, or show me how to spcify a pattern to grab the major version from a retrieved version string.

Many thanks,

Damien

Re: How to parse a version number

Posted: Mon Jan 11, 2016 6:49 am
by bokkie
Damien,

I used the parse string statement and it worked okay. I've attached a project (based on the blank template) containing an example. Open it and inspect the parse string statement to see what I used. It works on any number of characters before the first "." token.

Does it do what you want to do?

Re: How to parse a version number

Posted: Mon Jan 11, 2016 7:07 am
by Dame1701
That's fantastic bokkie, that you so much for the example it is incredibly simple. For anyone just reading this post, the pattern simply needs to be set to a full stop e.g. "." (don't add the quotes) then you can just tell it to match up until that point.

Re: How to parse a version number

Posted: Mon Jan 11, 2016 7:16 am
by bokkie
Glad to have helped. I sometimes come up with over-the-top answers but this was one of those slap-my-own-face problems because it seemed just "too simple". :D

What was a little confusing is the the MSIcode statement doesn't tell you what delimiter is used. You only see it when you select the statement and press [RETURN] to open its dialog. Maybe the dev team might consider adding it to the visible MSIcode statement?