我在 SQL Server 中有一个 View ,可以将一种模式版本转换为另一种模式版本。
目前, View 如下所示:
SELECT newValue AS oldValue
FROM dbo.MyTable
问题在于,在新架构中,newValue 不可为空,因此我们将其设置为 -1 以表示空字段,但在旧架构中,它是可为空的。
我怎样做才能达到以下效果:
SELECT
(
IF( newValue > -1 )
newValue as oldValue
ELSE
NULL as oldValue
)
FROM dbo.MyTable
最佳答案
SELECT
case when newValue > -1 then
newValue
else
NULL
end as oldValue
FROM dbo.MyTable
关于sql - 在 SQL Server View 中使用 IF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3517062/