SQL CASE 语句(将 CASE 语句保留在 WHERE 子句中)
我有一个名为:
Ext_Meeting_Status
它具有字段
- Ext_Meeting_Status_ID
- TEXT
值是:
EXT_Meeting_Status_ID Text
1 Draft
2 Published
3 Cancelled
4 Closed
如果日期是今天,我如何返回“已发布”的“文本”字段,否则返回“关闭”。
我尝试使用:
select * from Ext_Meeting_Status
where
GETDATE() = CASE
WHEN ( GETDATE() = '2010-12-13 10:02:31.560' )
THEN ( Ext_Meeting_Status_ID=2)
ELSE ( Ext_Meeting_Status_ID=4)
END
I have a table named:
Ext_Meeting_Status
This has fields
- Ext_Meeting_Status_ID
- TEXT
The values are:
EXT_Meeting_Status_ID Text
1 Draft
2 Published
3 Cancelled
4 Closed
How do i return the "Text" field of "Published" if date is today, else return "Close".
I tried using:
select * from Ext_Meeting_Status
where
GETDATE() = CASE
WHEN ( GETDATE() = '2010-12-13 10:02:31.560' )
THEN ( Ext_Meeting_Status_ID=2)
ELSE ( Ext_Meeting_Status_ID=4)
END
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信这应该有效..
还有一个注意事项:将当前日期与精确的毫秒级别进行比较可能不起作用,因为当时查询可能无法执行...
您可以尝试类似的操作。
I believe this should work..
One more note : Comparing current date to the exact millisecond level might not work as the query may not get executed at that time...
You may try something like this.
我认为这是不可能的。您可能想尝试将其全部放入子选择中并在那里使用 CASE。
I don't think it's possible. You may want to try to put it all into a sub-select and use the CASE there.