select distinct *,count(*)
from (select 1
      union all
      select 2)看看记录数是多少,这样?

解决方案 »

  1.   

     if 1.0*select count(*) from (第一条语句 union 第二条语句)/(select count(*) from (第一条语句)  +(select count(*) from (第二条语句)
         =0.5
     print '结果完全相同'
     else
      print '结果不完全相同'
    试试
      

  2.   

    --前提:查出的结果中不能有text、ntext、image、cursor 数据类型的字段。
    --假设这两条语句为(不考虑语句的复杂程度,不考虑表,只考虑查询的结果)
    select * from tb1
    select * from tb2--如果没有记录则表示第一个查询的结果都包含在第二个查询的结果中
    select * from (select * from tb1) a where checksum(*) not in (select checksum(*) from (select * from tb2) b)--如果没有记录则表示第二个查询的结果都包含在第一个查询的结果中
    select * from (select * from tb2) a where checksum(*) not in (select checksum(*) from (select * from tb1) b)--假设两个语句查询出来的结果其字段,类型都一样。
    --如果没有记录则表示完全相等。
    select * from (select * from tb1) a where checksum(*) not in (select checksum(*) from (select * from tb2) b)
    union all
    select * from (select * from tb2) a where checksum(*) not in (select checksum(*) from (select * from tb1) b)