各位大俠: 本人現在正在編一個存儲過程,要求把一個表裡a的數據 插入到另一個表b,
同時a的某些列(組合主鍵) 不能已經存在 b中。
因為 b中部分列a中沒有,所以插入時查詢a的結果必須加入部分列的自定義值! 在這裡我真的搞不清怎麼做。
我的sql如下出錯!
insert into b(b.c1,b.c2,b.c3,b.c4,b.c5)
select distinct a.c1,a.c2,a.c3,CONVERT( CHAR(23),getdate(),21),'通過'
from a
where (a.c1,a.c2,a.c3) not exist(select c1,c2,c3 from b)
求各位大俠幫幫忙啊!
同時a的某些列(組合主鍵) 不能已經存在 b中。
因為 b中部分列a中沒有,所以插入時查詢a的結果必須加入部分列的自定義值! 在這裡我真的搞不清怎麼做。
我的sql如下出錯!
insert into b(b.c1,b.c2,b.c3,b.c4,b.c5)
select distinct a.c1,a.c2,a.c3,CONVERT( CHAR(23),getdate(),21),'通過'
from a
where (a.c1,a.c2,a.c3) not exist(select c1,c2,c3 from b)
求各位大俠幫幫忙啊!
select distinct a.c1,a.c2,a.c3,CONVERT( CHAR(23),getdate(),21),'通過'
from a
where not exists(select c1 from b Where c1 = a.c1 and c2 = a.c2 and c3 = a.c3)
是这个意思吗?
(
c1 varchar(10),
c2 varchar(20),
c3 varchar(10),
)
insert into a values('1','2','3')
insert into a values('1','2','3')
insert into a values('1','2','3')
insert into a values('1','2','3')select a.*,aa='tongguo' into b from a
select * from b我不知道这个是不是你想要的