SELECT CASE WHEN patindex('%.%.%.%',@@version) > 0 THEN cast(substring(@@version, patindex('%.%.%.%',@@version)-2,charindex('.',ltrim(substring(@@version, patindex('%.%.%.%',@@version)-2,8)))) as int) ELSE 0 END"
SELECT CASE WHEN patindex('%.%.%.%',@@version) > 0 THEN cast(substring(@@version, patindex('%.%.%.%',@@version)-2,charindex('.',ltrim(substring(@@version, patindex('%.%.%.%',@@version)-2,8)))) as int) ELSE 0 END
Error I get
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the nvarchar value '15.' to data type int.
We have no idea since we cannot see your data - or your expected results. Can you provide a sample in the form of a table and insert statement(s) of example data and the expected results from that data?
Need to subtract 1 from the CharIndex statement to remove the decimal
SELECT CASE WHEN patindex('%.%.%.%',@@version) > 0 THEN
cast(substring(@@version, patindex('%.%.%.%',@@version)-2,charindex('.',ltrim(substring(@@version, patindex('%.%.%.%',@@version)-2,8))) - 1) as int)
ELSE 0
END