--处理示例
declare @s nvarchar(4000)
select @s=N''
select @s=@s+N' and '+name+N'=a.'+name
from(
select name=quotename(name) from syscolumns
where id=object_id(N'[info]'))a
select @s=stuff(@s,1,4,'')
exec(N'select taxi_no
from [info] a
where not exists(
select * from wch..[info]
where'+@s+N')
group by taxi_no')
--找出 kf库info表中 除去 <与wch库的info表相同记录> 以外的记录
--只要有任何一个字段值不一样都视为不同.
--最后还要 Group by taxi_no(未放入group by 的字段必须放入聚合函数,所以假设其他字段都放入max中)
use kf
go
--处理示例
declare @s nvarchar(4000),@fd nvarchar(4000)
select @s=N'',@fd=N''
select @s=@s+N' and '+name+N'=a.'+name
,@fd=@fd+case
when name=N'[taxi_no]' then @fd
else @fd+N','+name+N'=max('+name+')' end
from(
select name=quotename(name) from syscolumns
where id=object_id(N'[info]'))a
select @s=stuff(@s,1,4,'')
exec(N'select [taxi_no]'+@fd+N'
from [info] a
where not exists(
select * from wch..[info]
where'+@s+N')
group by [taxi_no]')