UPDATE TABLE1 SET tecnicalclassmax='技师'
FROM TABLE1 ,(SELECT workid FROM table2 WHERE tecnicalclass='技师') B
WHERE TABLE1.workid=B.workidINSERT INTO table1
SELECT workid,'技师'
FROM   table2 A LEFT JOIN TABLE2 B ON tecnicalclass='技师' AND A.WORKID=B.WORKID
WHERE B.WORID IS NULL

解决方案 »

  1.   

    create trigger name for table2
    for insert,update
    as
    if exists(updated.tecnicalclass='技师')
    begin
        if exists( select 1 from table1 where table1.workid=updated.workid ) 
        begin
            update table1 set tecnicalclass='技师'where tabl1.workid=updated.workid
        end
        else
        begin
            insert into table1 select * from updated
        end
    end if exists(inserted.tecnicalclass='技师')
    begin
        if not exists( select 1 from table1 where table1.workid=inserted.workid )
        begin
           insert into table2 select * from inserted
        end
        else
        begin
           update table1 set tecnicalclass='技师'where tabl1.workid=inserted.workid
        end
    end       
      

  2.   

    UPDATE TABLE1 SET tecnicalclassmax='技师'
    FROM TABLE1 ,(SELECT workid FROM table2 WHERE tecnicalclass='技师') B
    WHERE TABLE1.workid=B.workidinsert into table1 s
    elect * from table2 
    where table2.tecnicalclass='技师' and table2.workid not in( select workid from table1)
      

  3.   

    update table1 set tecnicalclassmax=(select top 1 tecnicalclassmax from table2 where workid=table1.workid order by charindex(tecnicalclass,'技师,高级,中级,初级'))insert table1 select * from table2 tem where tecnicalclass=(select top 1 tecnicalclassmax from table2 where workid=tem.workid order by charindex(tecnicalclass,'技师,高级,中级,初级'))