在 SQL Server 视图中使用 IF
我在 SQL Server 中有一个视图,可以从一个架构版本转换为另一个架构版本。
目前,视图如下所示:
SELECT newValue AS oldValue
FROM dbo.MyTable
问题是,在新模式中,newValue 不可为空,因此我们将其设置为 -1 以表示空字段,但在旧模式中,它可以为空。
我怎样才能做一些事情来达到以下效果:
SELECT
(
IF( newValue > -1 )
newValue as oldValue
ELSE
NULL as oldValue
)
FROM dbo.MyTable
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)