列如表a有station和cause兩個欄位的資料,我想在表b中判斷表a的station和cause兩個欄位的資料都存在,不存在的寫到表b中,謝謝啦
uj5u.com熱心網友回復:
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)
兩個帖子都結貼吧
uj5u.com熱心網友回復:
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
uj5u.com熱心網友回復:
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 );
uj5u.com熱心網友回復:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/281879.html
標籤:應用實例
上一篇:數學建模問題求助
