select  count(*)
from [192.168.0.105].asmis.dbo.gbitem a where a.item_no not in ( select item_no from hgbitem)
是多少?

解决方案 »

  1.   

    奇怪.如果只计数,结果是否一样?1。select  count(*)
    from [192.168.0.105].asmis.dbo.gbitem a where  a.item_no not in ( select item_no from hgbitem)2。select count(*)
    from [192.168.0.105].asmis.dbo.gbitem a where  a.item_no not in ( select item_no from hgbitem)
      

  2.   

    用Exists吧,not in我也碰到过莫名奇妙的问题。
      

  3.   

    然后保证服务器上没有NOT IN 条件里的表
    最好是都写清楚,省的麻烦
      

  4.   

    回2楼,是39220,就是问题中第2个sql语句执行结果影响的行数。
    回3楼,你给的两个sql语句是一模一样的,结果也当然是一样的都是39220。
    回4楼,上述sql语句如何转化成用exists表示呢,请教。
      

  5.   

    回5楼,两条语句我放在一起执行的,在同一台电脑上执行。
    “然后保证服务器上没有NOT IN 条件里的表
    最好是都写清楚,省的麻烦”能说详细点吗?
      

  6.   

    下面的问题更邪门了:
    select *
    into #t1
    from [192.168.0.105].asmis.dbo.gbitem a where  a.item_no not in ( select item_no from hgbitem)
     
    select * from hgbitem
    where item_no in ( select item_no from #t1)
    drop table #t1我执行后居然检索出300多条记录,而且这些记录在hgbitem表中跟本就不存在!!
    结果集为空才对啊!
      

  7.   

    检查是否数据库有问题:DBCC CHECKDB('数据库名')
      

  8.   

    CHECKDB found 0 allocation errors and 0 consistency errors in database 'tax'.
      

  9.   

    那真是怪了a.item_no
    item_no是否有null记录
      

  10.   

    你的表中,有没有在item_no上建立索引,如果有的话,试试重建索引:DBCC DBREINDEX ('数据库名.dbo.表名')
      

  11.   

    你在hgbitem前也加上“机器名.数据库.dbo”试试
      

  12.   

    item_no在gbitem表和hgbitem表中均是主键,是索引了,也不可能有null值。我也查了确实没null值。
    风云的方法我先试一下。
    谢谢这么多热心的高手指点,小弟感激不尽。
      

  13.   

    试了一下风云的方法,还是不行,但我在item_no前加rtrim结果集就由39220行变成1169行了,
    难道非得加个rtrim吗?这样做速度慢的惊人!
      

  14.   

    这样得出的结果有否区别:
    1。select a.*
    ...
    2。select a.item_no
    ...