A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @Rob M
How about creating a UDF to add the different parts of version strings and return a BIGINT number, then you can apply this UDF in your filter clause to compare.
And, if your Version strings always have 3 dots(which means 4 differnt parts), then you could consider using Parsename function to split the version value by '.'
Check this sample:
IF OBJECT_ID('dbo.fn_Calculate_Version')IS NOT NULL
DROP FUNCTION dbo.fn_Calculate_Version;
GO
CREATE FUNCTION dbo.fn_Calculate_Version(@VersionValue VARCHAR(50))
RETURNS BIGINT
AS
BEGIN
DECLARE @Calculate_Version AS BIGINT;
SET @Calculate_Version =
Right('0000'+Coalesce(Parsename(@VersionValue, 4),''), 4) +
Right('0000'+Coalesce(Parsename(@VersionValue, 3),''), 4) +
Right('0000'+Coalesce(Parsename(@VersionValue, 2),''), 4) +
Right('0000'+Coalesce(Parsename(@VersionValue, 1),''), 4)
RETURN @Calculate_Version;
END
GO
CREATE Table #Version (Version VARCHAR(20))
INSERT INTO #Version VALUES('1.0.0.5'),('1.5.0.06'),('1.0.0.06'),('8.0.2020.8'),('8.0.730.0'),('8.1.680.7'),('12.15.1323.22'),('12.15.622.55')
SELECT Version,dbo.fn_Calculate_Version(Version)
FROM #Version
WHERE dbo.fn_Calculate_Version(Version)>dbo.fn_Calculate_Version('8.0.2020.8')
Note1: The above solution is based on the premise that the version string has only four parts.
Note2: If the Max digit of each part is not 4, suppose say 6.
Then you need to modify the UDF, change Right('0000'+Coalesce(Parsename(@VersionValue, 4),''), 4)+... to Right('000000'+Coalesce(Parsename(@VersionValue, 4),''), 6)+...
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.