日期:2014-05-18  浏览次数:20340 次

sql 2000一条记录同时插入多张表?
我写了一个触发器,在满足条件下,把新增记录同时插入多张表应该怎么操作?
if   条件
    insert   into   sms_send(mobile,content)  
    select   distinct   sms_receive.mobile   mobile,   '123 '   content  
    FROM     sms_receive
  else   if   条件
    insert   into   sms_send(mobile,content)  
      select   distinct   sms_receive.mobile   mobile,   '123 '   content  
      from   sms_receive
else
  insert   into   sms_send(mobile,content),SaveMobile(mobile)  
    select   distinct   sms_receive.mobile   mobile,       '123 '   content  
    from   sms_receive
  insert   into   SaveMobile(mobile)  
    select   distinct   sms_receive.content   mobile   from   sms_receive
应该怎么写在最后一个insert不会做判断,不满足条件的也会插入SaveMobile,
请教应该怎么写?

------解决方案--------------------
if 条件
begin
insert into sms_send(mobile,content)
select distinct sms_receive.mobile mobile, '123 ' content
FROM sms_receive
end
else if 条件
begin
insert into sms_send(mobile,content)
select distinct sms_receive.mobile mobile, '123 ' content
from sms_receive
end
else
begin
insert into sms_send(mobile,content),SaveMobile(mobile)
select distinct sms_receive.mobile mobile, '123 ' content
from sms_receive
end
insert into SaveMobile(mobile)
select distinct sms_receive.content mobile from sms_receive