我试图在SQL Server数据库的version
列中映射信息。现在,我们的值从v1.x.x.x.x
到v23.x.x.x.x
,我想要的是:
case
when left(version,3) is v9. then 'v9',
when left(version,4) is v10. then 'v10',
when left(version,3) is between v1. and v8. then 'old'
end as 'version'
但我收到此错误:
关键字'然后'
附近的语法不正确
谢谢!
答案 0 :(得分:0)
这是正确的方法
declare @version varchar(10) = 'v2.tyt'
SELECT CASE
WHEN Substring(@version, 2, Charindex('.', @version) - 2) <= 8 THEN 'old'
WHEN Substring(@version, 2, Charindex('.', @version) - 2) IN ( 9, 10 ) THEN 'v' + Substring(@version, 2, Charindex('.', @version)-2)
END
注意:这始终认为数据的格式是这样的
A character|any numeric value|.|anything