在 T-Sql 的条件中使用 Null 变量
有没有一种方法可以按以下方式使用变量?
DECLARE @ID int;
SET @ID = NULL;
SELECT *
FROM Market market
WHERE market.ID IS @ID
或者还有其他方法可以做到这一点吗?
谢谢。
Is there a way to use a variable in the following manner?
DECLARE @ID int;
SET @ID = NULL;
SELECT *
FROM Market market
WHERE market.ID IS @ID
Or is there another way to do this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要这样做
只是为了完整性,目前仍然可以这样做
,但您不应该这样做。此选项已弃用。 相当有趣的相关博客文章
You need to do
Just for completeness at the moment it is still possible to do
but you shouldn't. This option is deprecated. Quite an interesting related blog post
您尝试将 null 粘贴到变量中而不是仅仅执行以下操作是否有特殊原因:
Is there a particular reason that you are trying to stick null into a variable rather than just doing:
如果您只想确定 market.ID 是否为 null,您可以这样做
如果您正在测试 market.ID 是否为 null 或其他值,请尝试此操作
If you just want to determine if market.ID is null, you would do this
If you're testing to see if market.ID is null or some other value then try this