34,590
社区成员
发帖
与我相关
我的任务
分享
if not object_id('tempdb..#tmp_A') is null
drop table #tmp_A
go
create table #tmp_A(
spdm varchar(10),
ggdm varchar(10))
go
insert into #tmp_A
Select '001','032' union all
Select '001','038' union all
Select '001','756' union all
Select '002','125' union all
Select '002','300'
GO
if not object_id('tempdb..#tmp_B') is null
drop table #tmp_B
go
create table #tmp_B(
spdm varchar(10),
gg1dm varchar(10))
go
insert into #tmp_B
Select '001','006' union all
Select '001','038' union all
Select '001','756' union all
Select '002','350' union all
Select '002','300'
Select *
FROM #tmp_B b
Where not exists (Select 1 From #tmp_A a Where a.spdm=b.spdm and a.ggdm=b.gg1dm)
spdm gg1dm
---------- ----------
001 006
002 350
--测试数据
if not object_id(N'Tempdb..#a') is null
drop table #a
Go
Create table #a([spdm] nvarchar(23),[ggdm] nvarchar(23))
Insert #a
select N'001',N'032' union all
select N'001',N'038' union all
select N'001',N'756' union all
select N'002',N'125' union all
select N'002',N'300'
GO
if not object_id(N'Tempdb..#b') is null
drop table #b
Go
Create table #b([spdm] nvarchar(23),[gg1dm] nvarchar(23))
Insert #b
select N'001',N'006' union all
select N'001',N'038' union all
select N'001',N'756' union all
select N'002',N'350' union all
select N'002',N'300'
Go
--测试数据结束
SELECT *
FROM #b
WHERE NOT EXISTS ( SELECT *
FROM #a
WHERE #a.spdm = #b.spdm
AND #a.ggdm = #b.gg1dm )