码迷,mamicode.com
首页 > 数据库 > 详细

T-SQL not in 遇到 null 暗含的陷阱

时间:2016-01-28 12:35:27      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

下面有两个T-SQL,乍看之下以为是等效的,实际却不是这样

                         SELECT orderid1 ,
                                LocalCost ,
                                supplyGoodsName ,
                                buyersgoodsid ,
                                JSitId ,
                                GSitId
                         FROM   csc_result WITH ( NOLOCK )
                         WHERE  [level] > 0
                                AND orderid1 LIKE ‘618464266%‘
                                AND ( supplygoodsid NOT IN ( 1085317, 1112957 ) )

技术分享

                         SELECT     orderid1,
                                    LocalCost ,
                                    supplyGoodsName ,
                                    buyersgoodsid ,
                                    JSitId ,
                                    GSitId
                          FROM      csc_result WITH ( NOLOCK )
                          WHERE     [level] > 0
                                    AND orderid1 LIKE ‘618464266%‘
                                    AND (supplygoodsid  NOT IN ( 1085317,
                                                              1112957 )
                                                              OR SupplyGoodsId IS NULL)

技术分享

可见not in并不能把null值排除在外

T-SQL not in 遇到 null 暗含的陷阱

标签:

原文地址:http://blog.csdn.net/lee576/article/details/50599729

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!