update lectinning set istatus=2 ,stime=case when stime is null then else stime end ,etime=case when etime is null then else etime end ,sip=case when sip is null then #uip# else sip end ,eip=case when eip is null then #uip# else eip end ,ispcs=case when ispcs is null then 1 else ispcs end ,ispce=case when ispce is null then 1 else ispce end ,statustime= ,statusreason=#statusreason# ,statususerno=#uno# where lectno in ($lectnos$) and (istatus is null or istatus<2); insert into lectinning(lectno,cmino,totstudy,stime,etime,istatus,statustime,statusreason,statususerno,) select a.lectno,b.cmino,0,,,2,,#statusreason#,#uno#, from lect a inner join cminning b on b.cmno=a.cmno left outer join lectinning c on c.lectno=a.lectno and c.cmino=b.cmino where a.lectno in ($lectnos$) and a.status=1 and a.ischanged=0 and c.lectno is null; update lect set ,attrate=100 ,stime=case when stime is null then else stime end ,etime=case when etime is null then else etime end ,sip=case when sip is null then #uip# else sip end ,eip=case when eip is null then #uip# else eip end ,ispcs=case when ispcs is null then 1 else ispcs end ,ispce=case when ispce is null then 1 else ispce end where lectno in ($lectnos$) update lectinning a inner join ( select #Ds[].lectno# lectno,#Ds[].istatus# istatus ) b on b.lectno=a.lectno set a.uip=#uip#,a.uno=#uno# ,a.istatus=b.istatus ,a.stime = a.stime ,a.etime = a.etime ,a.sip = case when a.sip is null then #uip# else a.sip end ,a.eip = case when a.eip is null then #uip# else a.eip end ,a.ispcs = case when a.ispcs is null then 1 else a.ispcs end ,a.ispce = case when a.ispce is null then 1 else a.ispce end where a.cmino=#cmino#; insert into lectinning (lectno,cmino,totstudy,istatus,statustime,statusreason,sip,eip,ispcs,ispce,) select a.lectno,#cmino#,0 ,a.istatus,null,null,#uip#,#uip#,1,1, from ( select #Ds[].lectno# lectno,#Ds[].istatus# istatus ) a left outer join lectinning b on b.cmino=#cmino# and b.lectno=a.lectno where b.lectno is null; update lect a inner join ( select a.lectno,convert(100*count(c.lectno)/count(b.cmino), int) attrate from lect a inner join cminning b on b.cmno=a.cmno and ifnull(b.isscd,0)=0 left outer join lectinning c on c.lectno=a.lectno and c.cmino=b.cmino and c.istatus in (1,2) where a.lectno in ($lectnos$) group by a.lectno ) b on b.lectno=a.lectno set a.attrate=b.attrate ,a.stime=case when a.stime is null then else a.stime end ,a.etime=case when a.etime is null then else a.etime end ,a.sip=case when a.sip is null then #uip# else a.sip end ,a.eip=case when a.eip is null then #uip# else a.eip end ,a.ispcs=case when a.ispcs is null then 1 else a.ispcs end ,a.ispce=case when a.ispce is null then 1 else a.ispce end update lectinning a inner join ( select #Ds[].lectno# lectno,#Ds[].cmino# cmino,#Ds[].istatus# istatus ) b on b.lectno=a.lectno and b.cmino = a.cmino set a.uip=#uip#,a.uno=#uno# ,a.istatus=b.istatus ,a.stime = a.stime ,a.etime = a.etime ,a.sip = case when a.sip is null then #uip# else a.sip end ,a.eip = case when a.eip is null then #uip# else a.eip end ,a.ispcs = case when a.ispcs is null then 1 else a.ispcs end ,a.ispce = case when a.ispce is null then 1 else a.ispce end; insert into lectinning (lectno,cmino,totstudy,istatus,statustime,statusreason,sip,eip,ispcs,ispce,) select a.lectno,a.cmino,0 ,a.istatus,null,null,#uip#,#uip#,1,1, from ( select #Ds[].lectno# lectno,#Ds[].cmino# cmino,#Ds[].istatus# istatus ) a left outer join lectinning b on b.cmino=a.cmino and b.lectno=a.lectno where b.lectno is null; update lect a inner join ( select a.lectno,convert(100*count(c.lectno)/count(b.cmino), int) attrate from lect a inner join cminning b on b.cmno=a.cmno and ifnull(b.isscd,0)=0 left outer join lectinning c on c.lectno=a.lectno and c.cmino=b.cmino and c.istatus in (1,2) where a.lectno in ($lectnos$) group by a.lectno ) b on b.lectno=a.lectno set a.attrate=b.attrate ,a.stime=case when a.stime is null then else a.stime end ,a.etime=case when a.etime is null then else a.etime end ,a.sip=case when a.sip is null then #uip# else a.sip end ,a.eip=case when a.eip is null then #uip# else a.eip end ,a.ispcs=case when a.ispcs is null then 1 else a.ispcs end ,a.ispce=case when a.ispce is null then 1 else a.ispce end; update lectinning set ,lectno=#lectno#,cmino=#cmino#,totstudy=0 ,stime=,etime=null ,istatus=1,statustime=null,statusreason=null where lectno=#lectno# and cmino=#cmino# and istatus is null; insert into lectinning (lectno,cmino,totstudy,stime,etime,istatus,statustime,statusreason,sip,eip,ispcs,ispce,) select #lectno#,#cmino#,0,,null,1,null,null,#uip#,null,1,null, from (select 1 col1) a left outer join lectinning b on b.lectno=#lectno# and b.cmino=#cmino# where b.lectno is null; update lect set stime = case when stime is null then else stime end ,sip = case when sip is null then #uip# else sip end ,ispcs = case when ispcs is null then 1 else ispcs end where lectno=#lectno# update lectinning set ,totstudy=timestampdiff(SECOND, stime, ) ,etime= ,eip=#uip# ,ispce=1 ,istatus=2 where lectno=#lectno# and cmino=#cmino# and istatus=1; update lect a inner join ( select a.lectno,convert(100*count(c.lectno)/count(b.cmino), int) attrate from lectinning a inner join cminning b on b.cmino=a.cmino and ifnull(b.isscd,0)=0 left outer join lectinning c on c.lectno=a.lectno and c.cmino=b.cmino and c.istatus=2 where a.lectno=#lectno# and a.cmino=#cmino# and a.istatus=2 group by a.lectno ) b on b.lectno=a.lectno set a.attrate=b.attrate ,a.etime=,a.eip=#uip#,a.ispce=1 update lectinning set istatus=2 ,stime=case when stime is null then else stime end ,etime=case when etime is null then else etime end ,sip=case when sip is null then #uip# else sip end ,eip=case when eip is null then #uip# else eip end ,ispcs=case when ispcs is null then 1 else ispcs end ,ispce=case when ispce is null then 1 else ispce end ,statustime= ,statusreason=#statusreason# ,statususerno=#uno# where lectno=#lectno# and cmino=#cmino# and (istatus is null or istatus<2); insert into lectinning(lectno,cmino,totstudy,stime,etime,istatus,statustime,statusreason,statususerno,) select a.lectno,#cmino#,0,,,2,,#statusreason#,#uno#, from lect a left outer join lectinning b on b.lectno=a.lectno and b.cmino=#cmino# where a.lectno=#lectno# and a.status=1 and a.ischanged=0 and b.lectno is null; update lect a inner join ( select a.lectno,convert(100*count(c.lectno)/count(b.cmino), int) attrate from lectinning a inner join lect a2 on a2.lectno=a.lectno inner join cminning b on b.cmno=a2.cmno and ifnull(b.isscd,0)=0 left outer join lectinning c on c.lectno=a.lectno and c.cmino=b.cmino and c.istatus=2 where a.lectno=#lectno# and a.cmino=#cmino# and a.istatus=2 group by a.lectno ) b on b.lectno=a.lectno set a.attrate=b.attrate ,a.stime=case when a.stime is null then else a.stime end ,a.etime=case when a.etime is null then else a.etime end ,a.sip=case when a.sip is null then #uip# else a.sip end ,a.eip=case when a.eip is null then #uip# else a.eip end ,a.ispcs=case when a.ispcs is null then 1 else a.ispcs end ,a.ispce=case when a.ispce is null then 1 else a.ispce end where a.lectno=#lectno#