Note that there are some explanatory texts on larger screens.

plurals
  1. POGreater than or less than operators and versions
    primarykey
    data
    text
    <p>I have a MS SQL query that I am creating and I need to determine if a particular record falls into a "new" or "old" category based off of the version number. </p> <p>There is a column 'VersionNum' and the old version is any version number from 2.75.99.99 and below while the new version is any version number from 2.76.00.00 and up. The data type for the column is varchar(20). </p> <p>I was thinking about taking a subset of the string from X.XX and casting this as a decimal. Then once all versions are cast to a X.XX decimal I can determine old or new by performing a > or &lt; in a case statement within the select. </p> <p>Would this be the correct or idea way of going about deciding where the version numbers fall? Or is there some other method. I only ask because I would imagine that something similar to this is needed else where and this is not a unique situation. </p> <p>EDIT: One additional issue. There are some versions that are not X.XX.XX.XX (2.76.00.00) and some are in the form: 8.00.00 and would be considered "Old" versions. This confuses the system a lot more than I once thought. I did get information that the 5 digit version (8.00.00) is considered old all the time. So whenever there are 5 digits, the version is old. So I am thinking I would perform a case statement similar to:</p> <pre><code>SELECT Old = CASE WHEN LEN(VersionNum) &lt; 10 THEN 1 WHEN CAST(SUBSTRING(VersionNum,1,4) AS DECIMAL(5,2)) &lt; 1.52 AND LEN(VersionNum) &gt;= 10 THEN 1 ELSE 0 END, New = CASE WHEN CAST(SUBSTRING(VersionNum,1,4) AS DECIMAL(5,3)) &gt;= 1.52 AND LEN(VersionNum) &gt;= 10 THEN 1 ELSE 0 END FROM VersionTable </code></pre> <p>Is my logic correct? Or am I missing something. The inequality in the lengths is very annoying. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload