I have an MS SQL query that I am creating and I need to determine if a particular entry falls into the βnewβ or βoldβ category based on the version number.
There is a column called "VersionNum", and the old version is any version number from 2.75.99.99 and lower, and the new version is any version number from 2.76.00.00 and higher. The data type for the column is varchar (20).
I was thinking about taking a subset of the string from X.XX and doing it as a decimal. Then, as soon as all versions are transferred to the decimal number of X.XX, I can determine the old or new by doing a> or <in the case expression within select.
Would this be the right or ideological way to decide where version numbers fall? Or is there some other method. I just ask because I would suggest that something like this is needed somewhere else, and this is not a unique situation.
EDIT: Another problem. There are several versions that are not X.XX.XX.XX (2.76.00.00), and some of them are presented in the form: 8.00.00 and will be considered "old" versions. This confuses the system much more than I once thought. I received information that the 5-digit version (8.00.00) is considered old all the time. Therefore, when there are 5 digits, the version is old. Therefore, I think I would execute an operator similar to:
SELECT
Old = CASE WHEN LEN(VersionNum) < 10 THEN 1
WHEN CAST(SUBSTRING(VersionNum,1,4) AS DECIMAL(5,2)) < 1.52
AND LEN(VersionNum) >= 10 THEN 1
ELSE 0
END,
New = CASE WHEN CAST(SUBSTRING(VersionNum,1,4) AS DECIMAL(5,3)) >= 1.52
AND LEN(VersionNum) >= 10 THEN 1
ELSE 0
END
FROM
VersionTable
Is my logic correct? Or am I missing something. Inequality in lengths is very annoying.
source
share