How to parse a version number

Got a problem you cannot solve? Try here.
Dame1701
Posts: 29
Joined: Tue Jan 05, 2016 10:33 am

How to parse a version number

Postby Dame1701 » Mon Jan 11, 2016 6:06 am

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

bokkie
Posts: 767
Joined: Sun Feb 08, 2009 6:30 am

Re: How to parse a version number

Postby bokkie » Mon Jan 11, 2016 6:49 am

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?
Attachments
TestParse.7z
(978 Bytes) Downloaded 323 times
Peter. Smartly dressed, he still resembles an unmade bed.
InstallAware MVP

Dame1701
Posts: 29
Joined: Tue Jan 05, 2016 10:33 am

Re: How to parse a version number

Postby Dame1701 » Mon Jan 11, 2016 7:07 am

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.

bokkie
Posts: 767
Joined: Sun Feb 08, 2009 6:30 am

Re: How to parse a version number

Postby bokkie » Mon Jan 11, 2016 7:16 am

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?
Peter. Smartly dressed, he still resembles an unmade bed.
InstallAware MVP


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 173 guests