How to compare software versions using SQL Server?

后端 未结 16 2232
清酒与你
清酒与你 2020-12-03 07:30

When trying to compare software versions 5.12 to 5.8, version 5.12 is newer, however mathematically 5.12 is less than 5.8. How would I compare the two versions so that a new

16条回答
  •  醉话见心
    2020-12-03 08:30

    You could use hierarchyid Which you can use by putting a / at the end and start of the string and casting it

    e.g.

    SELECT CASE WHEN cast('/5.12/' as hierarchyid) > cast('/5.8/' as hierarchyid) THEN 'Y' ELSE 'N' END

    That returns a Y

提交回复
热议问题