我需要进行选择,将值转换为int并在另一个列中设置一个数字。
Select * ,
(CASE WHEN City='London' then '2' ELSE '1' END) as Status
from customers
问题是我想在INT中转换2:
select * ,
(CASE WHEN City='London' then CAST(City as int) '2' ELSE '1' END) as Status
from customers
似乎在THEN中仅接受一项操作?
答案 0 :(得分:0)
您可以尝试
SELECT * ,
(CASE WHEN City = 'London' THEN CAST('2' AS INT) ELSE CAST('1' AS INT) END) AS Status
FROM
customers
或
SELECT * ,
(CASE WHEN City = 'London' THEN 2 ELSE 1 END) AS Status
FROM
customers
对于将城市名称转换为numeric
的情况,看来您在任何世界都无法将城市名称转换为整数似乎是不现实的。