--建立测试环境
Create Table #table1(xid int,xNum varchar(10))
--插入数据
insert into  #table1
select  1 ,'A' union all
select  2,'C' union all
select 2,'B' union all
select 3,'C' union all
select 3,'D' union all
select 4, '0'
  
--建立测试环境
Create Table #table2(xid int,xNum2 varchar(10))
--插入数据
insert into #table2
select 2,'H' union all
select 3,'F' union all
select 1 ,  'I' union all
select 1,   'K' /****
Result:
xID xNum xNum2
1 A I
1 Nul K
2 C H
2 B Null
3 C F
3 D Null
4 o Null
****/select id = identity(int,1,1),xid,xnum into #table11 from #table1
select  id = identity(int,1,1),xid,xnum2 into #table21 from #table2---这地方:
select a.xid,a.xnum,b.xnum2 from #table11 a left join #table21 b
on a.xid=b.xid and (select count(*) from #table11 where xid=a.xid and id<a.id)=(select count(*) from #table21 where xid=b.xid and id<b.id)union select a.xid,b.xnum,a.xnum2 from #table21 a left outer join #table11 b
on a.xid=b.xid and (select count(*) from  #table21 where xid=a.xid and id<a.id)=(select count(*) from #table11 where xid = b.xid and id<b.id)----上面的没问题:但是用right join的话
select b.xid,a.xnum,b.xnum2 from #table11 a right outer join #table21 b
on a.xid=b.xid and (select count(*) from #table21 where  id< b.id  )>0
便会出现
ODBC: 消息 0,级别 19,状态 1
SqlDumpExceptionHandler: 进程 230 发生了严重的异常 c0000005 EXCEPTION_ACCESS_VIOLATION。SQL Server 将终止该进程。错误,请问为什么会这样呢?

解决方案 »

  1.   

    是啊,我搜索了一下,以前就有用right join遇上过这个问题的,可是没有找到答案。
      

  2.   

    select a.xid,b.xnum,a.xnum2 from #table21 a left outer join #table11 b
    on a.xid=b.xid and (select count(*) from  #table21 where xid=a.xid and id<a.id)=(select count(*) from #table11 where xid = b.xid and id<b.id)和select b.xid,a.xnum,b.xnum2 from #table11 a right outer join #table21 b
    on a.xid=b.xid and (select count(*) from #table11 where xid=a.xid and id<a.id)=(select count(*) from #table21 where xid=b.xid and id<b.id)本来应该是一样的语句,但是下一个出错
      

  3.   

    2000 补丁装到sp4也没有问题.没有装补丁就有问题.没有环境, 不知道sp1, sp2, sp3这几个版本的补丁是否修复了此问题.
      

  4.   

    这是一个BUG刚刚找到了sp3的环境, 在sql 2000+sp3下也有这个问题, 看来要解决的话, 必须升级到sql sp4或者sql 2005了.
      

  5.   

    我测试也没有问题.SQL sever 2005
      

  6.   

    刚才查了下,数据库是sp3补丁,在http://support.microsoft.com/kb/839458/这也提到这个错误,不过不是由right join 引起的,也是建议打sp4补丁
      

  7.   

    看来Haiwer(海阔天空)的sqlserver也没打sp4补丁  ^_*
      

  8.   

    打上sp4后,可以正常运行上面的right join了