日期:2014-05-18 浏览次数:20688 次
if not exists(select 1 from a where 名字='c') insert into a select 名字,年龄,... insert into b select a_id,.成绩 else update a set ... insert into b select .. where not exists(select 1 from b where 成绩=@成绩 and 学科=@学科)
------解决方案--------------------
declare @CId int set @CId=0 select @CId=ID from A where [名字]='C' if (@CId>0) begin update A set ... where [名字]='C' if not exists (select top (1) * from B where A_id=@CId and [学科]='语文') begin insert into B (A_id,[学科],[成绩]) values (@CId,'语文',85) end end else begin insert into A ([名字],[年龄]) values ('C',21) set @CId =SCOPE_IDENTITY() insert into B (A_id,[学科],[成绩]) values (@CId,'语文',85) end