目前有3个表 :
    A职工表(职工编号,Bid,.....); did是引用B表的外键
    B部门工资设置(Bid,工资1,工资2);
    C工资表(Cid,职工编号,工资1,工资2);需要一个存储过程:在C表中插入一个职工编号时候,同时初始化工资1和工资2。其中,工资1和工资2的值由A表和B表联合查询得到 (也就是不同部门的工资标准不一样)现在脑袋有点迷糊,请高手们帮忙指点一下  非常感谢

解决方案 »

  1.   


    create trigger tri_c
    on C工资表
    for insert
    as
    begin
    update c set c.工资1=b.工资1,c.工资2=b.工资2 
    from C工资表 c ,inserted i ,A职工表 a,B部门工资设置 b
    where i.Cid=c.Cid and i.职工编号=a.职工编号 and a.Bid=b.Bid
    end
      

  2.   


    谢谢 非常感谢 另外还有个销售额的问题  A职工表(职工编号,Bid,销售量.....); did是引用B表的外键
     B部门工资设置(Bid,工资1,工资2,单个销售额 );
     C工资表(Cid,职工编号,工资1,工资2,销售额);销售额的计算
    c.销售额=b.单个销售额*a.销售量  这样可以吗
      

  3.   

    create trigger tri_wageinfo
    on wageinfo
    for insert
    as
    begin
    update wageinfo set 
    wageinfo.postsalary=wl.postsalary, 
    wageinfo.Allowance=wl.Allowance,
    wageinfo.Bonus=wl.Bonus,
    wageinfo.Classhour = wl.Classhours*b.Classhour,
    wageinfo.endowmentins =(wl.postsalary+( wl.Classhours*b.Classhour))*0.08,
    wageinfo.unemployedins =(wl.postsalary+( wl.Classhours*b.Classhour))*0.002,
    wageinfo.medicalins =(wl.postsalary+( wl.Classhours*b.Classhour))*0.02+3,
    wageinfo.accfund = (wl.postsalary+( wl.Classhours*b.Classhour))*wl.accfundper*0.001from  inserted i ,baseinfo b,wagelevel wl
    where i.wid=wageinfo.wid and i.tid=b.tid and   b.jobid=wl.jobid
    end 终于写出来了