开发者

using IF in a SQL Server View

开发者 https://www.devze.com 2023-01-12 08:28 出处:网络
I have a view in SQL server that translates from one schema version to another. Currently, the view looks like this:

I have a view in SQL server that translates from one schema version to another.

Currently, the view looks like this:

SELECT newValue AS oldValue  
FROM dbo.MyTable

The trouble开发者_Python百科 is that, in the new schema, newValue is not nullable, so we set it to -1 to denote empty fields, but in the old schema, it was nullable.

How can I do something to the effect of:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号