发布网友 发布时间:2022-04-07 17:10
共2个回答
懂视网 时间:2022-04-07 21:31
where p.CurrDate between @DateBegin and @DateEnd
and DispatchNo<>‘‘
and (@EmpID = ‘‘ or e.EmpID = @EmpID or e.EmpName like @EmpID +‘%‘)
order by p.CurrDate, p.BCCode, p.MachineNo
update a set a.PlanProductTime=b.PlanProductTime
from #DailyTableEmp a
inner join #PlanTime b on a.MachineNo=b.MachineNo and a.BCCode=b.BCCode
update #DailyTableEmp set SocketRate=case when StandSocketNum=0 then 0 else SocketNum/(StandSocketNum*1.0) end--出数率
, BadRate=case when ProductedNum=0 then 0 else BadNum/(ProductedNum*1.0) end--不良率
, EfficiencyRate=case when TheoreticalQty=0 then 0 else ProductedNum/(TheoreticalQty*1.0) end--机台效率(有效率)
--, Availability=case when DispatchTime-NoPlanTime=0 then 0 else RealMacTime/(DispatchTime-NoPlanTime-PermissionTime) end--有效开机率(表现性,有效性)
, Availability=case when DispatchTime-NoPlanTime-PermissionTime-DaiRen=0 then 0 else RealMacTime/(DispatchTime-NoPlanTime-PermissionTime-DaiRen) end--有效开机率(表现性,有效性)
where Flag=2
update #DailyTableEmp set OEE=EfficiencyRate*Availability*(1-BadRate)--机台效率*有效开机率*良率
where Flag=2
--派工单层的OEE导入完成
--==================================================================================================================================
insert into #PlanTime
select distinct MachineNo, PlanProductTime, BCCode from #DailyTableEmp where CurrDate between @DateBegin and @DateEnd
insert into #DailyTableEmp(MachineNo,EmpGroupNO, EmpID, CurrDate, BCCode, StandSocketNum, SocketNum, TZ_StandEmp, ActualEmp, DispatchTime, RealMacTime, NoPlanTime, HuanMo, HuanLiao, HuanDan, JiQiGuZhang, MoJuGuZhang, FuSheGuZhang, DaiLiao, WuDingDan, QiTa, DaiRen, MacIdleTime, PermissionTime, PlanOutputQty, ActualOutputQty, PackageNum, TheoreticalQty, ProductedNum, BadNum, Flag)
select MachineNo, EmpGroupNO, EmpID, CurrDate, BCCode, SUM(StandSocketNum), SUM(SocketNum), SUM(TZ_StandEmp), SUM(ActualEmp), SUM(DispatchTime/ProductNum), SUM(RealMacTime/ProductNum), SUM(NoPlanTime/ProductNum), SUM(HuanMo/ProductNum), SUM(HuanLiao/ProductNum), SUM(HuanDan/ProductNum), SUM(JiQiGuZhang/ProductNum), SUM(MoJuGuZhang/ProductNum), SUM(FuSheGuZhang/ProductNum), SUM(DaiLiao/ProductNum), SUM(WuDingDan/ProductNum), SUM(QiTa/ProductNum), SUM(DaiRen/ProductNum), SUM(MacIdleTime/ProductNum), SUM(PermissionTime/ProductNum), SUM(PlanOutputQty), SUM(ActualOutputQty), SUM(PackageNum), SUM(TheoreticalQty), SUM(ProductedNum), SUM(BadNum),2
from #DailyTableEmp
where Flag in(0,1)
group by MachineNo,EmpGroupNO, EmpID, CurrDate, BCCode
update a set a.PlanProductTime=b.PlanProductTime from #DailyTableEmp a inner join #PlanTime b on a.MachineNo=b.MachineNo and a.BCCode=b.BCCode
update #DailyTableEmp set SocketRate=case when StandSocketNum=0 then 0 else SocketNum/(StandSocketNum*1.0) end--出数率
, BadRate=case when ProductedNum=0 then 0 else BadNum/(ProductedNum*1.0) end--不良率
, EfficiencyRate=case when TheoreticalQty=0 then 0 else ProductedNum/(TheoreticalQty*1.0) end--机台效率(有效率)
--, Availability=case when DispatchTime-NoPlanTime=0 then 0 else RealMacTime/(DispatchTime-NoPlanTime-PermissionTime) end--有效开机率(表现性,有效性)
, Availability=case when DispatchTime-NoPlanTime-PermissionTime-DaiRen=0 then 0 else RealMacTime/(DispatchTime-NoPlanTime-PermissionTime-DaiRen) end--有效开机率(表现性,有效性)
where Flag=2
update #DailyTableEmp set OEE=EfficiencyRate*Availability*(1-BadRate)--机台效率*有效开机率*良率
where Flag=2
--按机器编号层的OEE至此计算完成
--补充需求2013-05-27要求将所有派工单的产品名称用分号隔开对应到每台机器
--declare @rEmpGroupNO varchar(50), @rEmpNO varchar(50)
--declare cur_Daily cursor for
--select MachineNo, BCCode, ProductName, EmpGroupNO, EmpId from #DailyTableEmp where Flag in(0,1) and isnull(ProductName,‘‘)<>‘‘
--open cur_Daily
--fetch next from cur_Daily into @MachineNo, @BCCode, @ProductName, @rEmpGroupNO, @rEmpNO
--while @@FETCH_STATUS=0
--begin
-- print @MachineNo+ @BCCode+@ProductName
-- update #DailyTableEmp set ProductName=isnull(ProductName,‘‘)+@ProductName+‘; ‘
-- where Flag=2 and MachineNo=@MachineNo and BCCode=@BCCode and EmpGroupNO = @rEmpGroupNO and EmpID = @rEmpNO
-- fetch next from cur_Daily into @MachineNo, @BCCode, @ProductName, @rEmpGroupNO, @rEmpNO
--end
--close cur_Daily
--deallocate cur_Daily
--==================================================================================================================================
insert into #DailyTableEmp(EmpGroupNO,EmpID,CurrDate, BCCode, StandSocketNum, SocketNum, TZ_StandEmp, ActualEmp, DispatchTime, PlanProductTime, RealMacTime, NoPlanTime, HuanMo, HuanLiao, HuanDan, JiQiGuZhang, MoJuGuZhang, FuSheGuZhang, DaiLiao, WuDingDan, QiTa, DaiRen, MacIdleTime, PermissionTime, PlanOutputQty, ActualOutputQty, PackageNum, TheoreticalQty, ProductedNum, BadNum,Area, Flag)
select a.EmpGroupNO, a.EmpID, CurrDate, BCCode, SUM(StandSocketNum), SUM(SocketNum), SUM(TZ_StandEmp), SUM(ActualEmp), SUM(DispatchTime), SUM(PlanProductTime), SUM(RealMacTime), SUM(NoPlanTime), SUM(HuanMo), SUM(HuanLiao), SUM(HuanDan), SUM(JiQiGuZhang), SUM(MoJuGuZhang), SUM(FuSheGuZhang), SUM(DaiLiao), SUM(WuDingDan), SUM(QiTa), SUM(DaiRen), SUM(MacIdleTime), SUM(PermissionTime), SUM(PlanOutputQty), SUM(ActualOutputQty), SUM(PackageNum), SUM(TheoreticalQty), SUM(ProductedNum), SUM(BadNum),
‘‘, 3
from #DailyTableEmp a inner join MachineMstr b on a.MachineNo=b.Machine_Code
where Flag=2
group by a.EmpGroupNO, a.EmpID, CurrDate, BCCode
insert into #DailyTableEmp(EmpGroupNO,EmpID,CurrDate, BCCode, StandSocketNum, SocketNum, TZ_StandEmp, ActualEmp, DispatchTime, PlanProductTime, RealMacTime, NoPlanTime, HuanMo, HuanLiao, HuanDan, JiQiGuZhang, MoJuGuZhang, FuSheGuZhang, DaiLiao, WuDingDan, QiTa, DaiRen, MacIdleTime, PermissionTime, PlanOutputQty, ActualOutputQty, PackageNum, TheoreticalQty, ProductedNum, BadNum, Flag)
select ‘汇总‘,EmpID,‘‘, ‘‘, SUM(StandSocketNum), SUM(SocketNum), SUM(TZ_StandEmp), SUM(ActualEmp), SUM(DispatchTime), SUM(PlanProductTime), SUM(RealMacTime), SUM(NoPlanTime), SUM(HuanMo), SUM(HuanLiao), SUM(HuanDan), SUM(JiQiGuZhang), SUM(MoJuGuZhang), SUM(FuSheGuZhang), SUM(DaiLiao), SUM(WuDingDan), SUM(QiTa), SUM(DaiRen), SUM(MacIdleTime), SUM(PermissionTime), SUM(PlanOutputQty), SUM(ActualOutputQty), SUM(PackageNum), SUM(TheoreticalQty), SUM(ProductedNum), SUM(BadNum),3
from #DailyTableEmp a inner join MachineMstr b on a.MachineNo=b.Machine_Code
where Flag=2
group by EmpGroupNO, a.EmpID
update #DailyTableEmp set SocketRate=case when StandSocketNum=0 then 0 else SocketNum/(StandSocketNum*1.0) end--出数率
, BadRate=case when ProductedNum=0 then 0 else BadNum/(ProductedNum*1.0) end--不良率
, EfficiencyRate=case when TheoreticalQty=0 then 0 else ProductedNum/(TheoreticalQty*1.0) end--机台效率(有效率)
, Availability=case when DispatchTime-NoPlanTime-PermissionTime-DaiRen=0 then 0 else RealMacTime/(DispatchTime-NoPlanTime-PermissionTime-DaiRen) end--有效开机率(表现性,有效性)
--, Availability=case when PlanProductTime=0 then 0 else RealMacTime/(PlanProductTime-PermissionTime) end--有效开机率(表现性,有效性)
where Flag=3
update #DailyTableEmp set OEE=EfficiencyRate*Availability*(1-BadRate)--机台效率*有效开机率*良率
where Flag=3
--按人员层级的OEE至此计算完成
update #DailyTableEmp set StandSocketNum=null,SocketNum=null,SocketRate=null,TZ_StandEmp=null,ActualEmp=null,DispatchTime=null,
PlanProductTime=null,EfficiencyRate=null,Availability=null,BadNum=null,BadRate=null where EmpGroupNO=‘汇总‘
--==================================================================================================================================
if @GroupType=‘Detail‘
begin
select t.MachineNo,t.EmpID,CurrDate,case when t.BCCode=‘A‘ then ‘白班‘ when t.BCCode=‘B‘ then ‘晚班‘ else ‘‘ end as BCCode,DispatchNo,TZ_CustomerNo,ProductName,ProductNo,TZ_MONO,DispatchNum,StandSocketNum,SocketNum
,convert(varchar(10), CAST(SocketRate*100 as decimal(10,0)))+‘%‘ as SocketRate,StandCycle,AverageCycle
,convert(varchar(10), CAST(CycleDiffRate*100 as decimal(10,0)))+‘%‘ as CycleDiffRate,TZ_StandEmp,ActualEmp,DispatchTime, PlanProductTime,RealMacTime,NoPlanTime,HuanMo,HuanLiao,HuanDan,JiQiGuZhang,MoJuGuZhang,FuSheGuZhang,DaiLiao,WuDingDan,QiTa,DaiRen,MacIdleTime,PermissionTime,PlanOutputQty,ActualOutputQty,PackageNum,TheoreticalQty
, EfficiencyRate,Availability = isnull(Availability,0),BadNum,BadRate,OEE = ISNULL(OEE,0)
, EmpGroupName =(select top 1 EmpGroupName from MESAlarm.dbo.AlarmEmpGroup g where g.EmpGroupNo = t.EmpGroupNO)
, EmployeeName = e.EmpName
from #DailyTableEmp t
left join Kenta_EmpOEEConfig e on t.EmpID = e.EmpID
where t.Flag=2 and t.BCCode like ‘%‘+@BC+‘%‘
order by t.CurrDate, t.MachineNo, t.BCCode, t.DispatchNo
end
else if @GroupType=‘Sum‘
begin
select t.EmpGroupNO,case when t.EmpGroupNO=‘汇总‘ then ‘‘ else t.EmpID end EmpID,t.EmpID EmpID2, CurrDate, case when t.BCCode=‘A‘ then ‘白班‘ when t.BCCode=‘B‘ then ‘晚班‘ else ‘‘ end as BCCode,DispatchNo,TZ_CustomerNo,ProductName,ProductNo,TZ_MONO,DispatchNum,StandSocketNum,SocketNum
,convert(varchar(10), CAST(SocketRate*100 as decimal(10,0)))+‘%‘ as SocketRate,StandCycle,AverageCycle
,convert(varchar(10), CAST(CycleDiffRate*100 as decimal(10,0)))+‘%‘ as CycleDiffRate,TZ_StandEmp,ActualEmp,DispatchTime, PlanProductTime,RealMacTime,NoPlanTime,HuanMo,HuanLiao,HuanDan,JiQiGuZhang,MoJuGuZhang,FuSheGuZhang,DaiLiao,WuDingDan,QiTa,DaiRen,MacIdleTime,PermissionTime,PlanOutputQty,ActualOutputQty,PackageNum,TheoreticalQty
,EfficiencyRate,Availability,BadNum,case when t.EmpGroupNO=‘汇总‘ then ‘汇总‘ else convert(varchar(10),BadRate) end BadRate,OEE,
dbo.GetMachineArea(e.MachineNo) Area,case when t.EmpGroupNO=‘汇总‘ then ‘‘ else t.EmpGroupNo end EmpGroupName
, EmployeeName = case when t.EmpGroupNO=‘汇总‘ then ‘‘ else e.EmpName end
from #DailyTableEmp t
left join Kenta_EmpOEEConfig e on t.EmpID = e.EmpID
and ((t.CurrDate between e.startDate and e.EndDate) or (t.CurrDate>e.startDate and e.EndDate is null))
where t.Flag=3 and t.BCCode like ‘%‘+@BC+‘%‘
order by EmpID2, case when t.EmpGroupNO=‘汇总‘ then 2 else 1 end,t.CurrDate, t.MachineNo, BCCode, DispatchNo
end
drop table #DailyTableEmp
GO
表与表特定条件下的关联SQL
标签:
热心网友 时间:2022-04-07 18:39
多个条件用where……and……连接即可,举例如下:
1、创建测试表,插入数据:
2、要求查询计算机系并且是女生,年龄小于20岁的人的信息。可用如下语句:
如图,其中红线标注的地方就是多条件连接的方法:
追问我的数据库的表已经建立了,而且和窗体进行连接了。现在想在第一个下拉框显示部位,然后第二个下拉框显示相应的特征