读书人

求 一sql 於 select * where not ex

发布时间: 2012-03-26 15:46:56 作者: rapoo

求 一sql 於 select * where not exist(..)
各位大:

本人在正在一存程,要求把一表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)


求各位大忙啊!

[解决办法]
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 not exists(select c1 from b Where c1 = a.c1 and c2 = a.c2 and c3 = a.c3)
[解决办法]
你的意思是,将a表中的全部列插入到一个新建立的b表中,但是这个b表比a表中的列多,同时要b中不能存在a中的数据,判断依据是组合键不能重复
是这个意思吗?

读书人网 >SQL Server

热点推荐