27,579
社区成员
发帖
与我相关
我的任务
分享
if not exists(select 1 from syscolumns inner join sysobjects on sysobjects.id = syscolumns.id
where syscolumns.name = 'station' and syscolumns.name = 'cause' and sysobject.name = "B表'
begin
update B ……
end
MERGE INTO b target
USING a source
ON (target.station=source.station AND target.cause =source.cause )
WHEN NOT MATCHED THEN
INSERT (station,cause) VALUES (source.station,source.cause );
insert into 表b(station,cause)
select a.station,a.cause
from 表a a
left join 表b b
on a.station=b.station
and a.cause=b.cause
where b.station is null
insert into b(字段名)
select val
from (
select *
from a
unpivot(val for col in (station,cause)) p
) a
where not exists(select top 1 1 from b where 字段名=a.val)
两个帖子都结贴吧