create trigger 名 on 发送表
for insert
as
begin
  if exists(select 1 from 发送表 where cast(日期 as varchar(11))=cast(getdate() as varchar(11)))
    update 日统计表 set 记录条数=记录条数+1 where cast(日期 as varchar(11))=cast(getdate() as varchar(11)))
  else
    insert 日统计表 select * from inserted
end

解决方案 »

  1.   

    能够具体解释一下里面的语法错误吗
    我敲了半天
    [发送表] 是SendMsg
    [日统计表]是datebiao 
    可惜有错误帮忙找一找
    CREATE TRIGGER yes  ON [dbo].[269_139_SendMsg] 
    FOR INSERT
    AS begin
     if exists(select 1 from [dbo].[269_139_SendMsg]  where cast(SendMsg.sendtime as varchar(11))=cast(getdate() as varchar(11)))
     update  datebiao set type='2' where  cast(datebiao.ServerDate as varchar(11))=cast(getdate() as varchar(11))   
    else
      insert datebiao (type) values ('1')
    end
      

  2.   

    另外在 insert datebiao (type) values ('1')中我想把写入SendMsg中的type变量如果检测到datebiao中没有该type的话同样以变量的形式也写入到datebiao中,帮忙~~
    呵呵~~~~~~
      

  3.   

    CREATE TRIGGER yes  ON [dbo].[269_139_SendMsg] 
    FOR INSERT
    AS begin
     if exists(select * from [dbo].[269_139_SendMsg]  where cast(SendMsg.sendtime as varchar(11))=cast(getdate() as varchar(11)))
     update  datebiao set type='2' where  cast(datebiao.ServerDate as varchar(11))=cast(getdate() as varchar(11))   
    else
      insert datebiao (type) values select Type from Inserted
    end
    暂时这样改,如果还有错误请将错误信息贴出来
      

  4.   

    对不起!这句:
    insert datebiao (type) values select Type from Inserted
    应改为
    insert into datebiao (type) select Type from Inserted