@ -1632,64 +1632,153 @@ left join #Tempcccc cc on a.销售车辆号=cc.销售车辆号
drop table # Tcustt_TOCKQty
drop table # Tcustt_TOCKQty
- - 用 途 程 表 关 联 wip表拼出所有的检验数据
select a . ITEMCODE , a . ROUTECODE , a . OPCODE , a . OPType AS OPTIONALOP , a . OPControlSeq , b . LOTNO ,
isnull ( b . ACTIONRESULT , '~' ) as ACTIONRESULT , b . MOCODE , b . MOSEQ , d . molotcode into # Tcustttemp1
from ICSITEMROUTE2OPLot a with ( nolock )
left join icslotonwip b with ( nolock ) on a . ITEMCODE = b . ITEMCODE and a . ROUTECODE = b . ROUTECODE and a . OPCODE = b . OPCODE
inner join ( SELECT distinct a . ITEMCODE , a . ROUTECODE
from ICSITEMROUTE2OPLot a with ( nolock )
left join icslotonwip b with ( nolock ) on a . ITEMCODE = b . ITEMCODE and a . ROUTECODE = b . ROUTECODE and a . OPCODE = b . OPCODE
WHERE b . ACTIONRESULT is not null
) c on a . ITEMCODE = c . ITEMCODE and a . ROUTECODE = c . ROUTECODE
left join icsmo d with ( nolock ) on d . MOCODE = b . MOCODE and b . SEQ = d . MOSEQ
//--用途程表关联wip表拼出所有的检验数据
//select a.ITEMCODE,a.ROUTECODE,a.OPCODE, a.OPType AS OPTIONALOP, a.OPControlSeq,b.LOTNO,
//isnull(b.ACTIONRESULT,'~') as ACTIONRESULT,b.MOCODE,b.MOSEQ,d.molotcode into #Tcustttemp1
//from ICSITEMROUTE2OPLot a with(nolock)
//left join icslotonwip b with(nolock) on a.ITEMCODE = b.ITEMCODE and a.ROUTECODE = b.ROUTECODE and a.OPCODE = b.OPCODE
//inner join (SELECT distinct a.ITEMCODE,a.ROUTECODE
//from ICSITEMROUTE2OPLot a with(nolock)
//left join icslotonwip b with(nolock) on a.ITEMCODE = b.ITEMCODE and a.ROUTECODE = b.ROUTECODE and a.OPCODE = b.OPCODE
//WHERE b.ACTIONRESULT is not null
// ) c on a.ITEMCODE = c.ITEMCODE and a.ROUTECODE = c.ROUTECODE
//left join icsmo d with(nolock) on d.MOCODE = b.MOCODE and b.SEQ = d.MOSEQ
order by ITEMCODE , OPControlSeq
- - 把 wip表里有在开工的排除
select ITEMCODE , ROUTECODE , ACTIONRESULT into # Tcusttfilter from icslotonwip with ( nolock )
group by ITEMCODE , ROUTECODE , ACTIONRESULT HAVING COUNT ( ITEMCODE ) = 1 and COUNT ( ROUTECODE ) = 1
- - 找 出 待 检 的 工 序
select ITEMCODE , a . ROUTECODE , OPCODE , c . MOCODE , c . MOSEQ , c . LOTNO into # TcusttDJ from # Tcustttemp1 a
inner join
( select min ( OPControlSeq ) OPControlSeq , ROUTECODE from # Tcustttemp1 where OPTIONALOP = ' 检 验 工 序 ' and LOTNO is null - - 最 小 未 检 前 一 道 结 束 的
and ROUTECODE in
( select ROUTECODE from ( select max ( a . OPControlSeq ) OPControlSeq , a . ROUTECODE from # Tcustttemp1 a
inner join ( select min ( OPControlSeq ) OPControlSeq , ROUTECODE from # Tcustttemp1 where OPTIONALOP = ' 检 验 工 序 ' and LOTNO is null group by ROUTECODE ) b
on a . ROUTECODE = b . ROUTECODE and b . OPControlSeq > a . OPControlSeq and a . ACTIONRESULT = ' COLLECT_END ' group by a . ROUTECODE ) a )
GROUP BY ROUTECODE ) b
on a . ROUTECODE = b . ROUTECODE and a . OPControlSeq = b . OPControlSeq
inner join ( select distinct mocode , MOSEQ , ROUTECODE , LOTNO from icslotonwip with ( nolock ) ) c
on a . ROUTECODE = c . ROUTECODE
where
not EXISTS ( select 1 from # Tcusttfilter f
where f . ITEMCODE = a . ITEMCODE and f . ROUTECODE = a . ROUTECODE )
//order by ITEMCODE,OPControlSeq
//--把wip表里有在开工的排除
//select ITEMCODE,ROUTECODE,ACTIONRESULT into #Tcusttfilter from icslotonwip with(nolock)
//group by ITEMCODE,ROUTECODE,ACTIONRESULT HAVING COUNT(ITEMCODE) = 1 and COUNT(ROUTECODE)=1
//--找出待检的工序
//select ITEMCODE,a.ROUTECODE,OPCODE,c.MOCODE,c.MOSEQ,c.LOTNO into #TcusttDJ from #Tcustttemp1 a
//inner join
//(select min(OPControlSeq) OPControlSeq,ROUTECODE from #Tcustttemp1 where OPTIONALOP = '检验工序' and LOTNO is null--最小未检前一道结束的
//and ROUTECODE in
//(select ROUTECODE from (select max(a.OPControlSeq) OPControlSeq,a.ROUTECODE from #Tcustttemp1 a
//inner join (select min(OPControlSeq) OPControlSeq,ROUTECODE from #Tcustttemp1 where OPTIONALOP = '检验工序' and LOTNO is null group by ROUTECODE) b
//on a.ROUTECODE = b.ROUTECODE and b.OPControlSeq >a.OPControlSeq and a.ACTIONRESULT = 'COLLECT_END' group by a.ROUTECODE) a )
//GROUP BY ROUTECODE) b
//on a.ROUTECODE = b.ROUTECODE and a.OPControlSeq = b.OPControlSeq
//inner join ( select distinct mocode,MOSEQ,ROUTECODE,LOTNO from icslotonwip with(nolock) ) c
//on a.ROUTECODE =c.ROUTECODE
//where
//not EXISTS( select 1 from #Tcusttfilter f
// where f.ITEMCODE=a.ITEMCODE and f.ROUTECODE =a.ROUTECODE )
- - 将 数 据 拼 接 成 在 检 和 待 检 两 部 分
//--将数据拼接成在检和待检两部分
- - 1 、 待 检 验 数 据 待 检 车 辆
select count ( 1 ) Qty into # Tcustt_TOCKQty
from (
select b . molotCode [ 销 售 车 号 ] - - , dj . LOTNO [ 产 品 跟 踪 单 ] , dj . OPCODE [ 工 序 代 码 ]
from # TcusttDJ dj
inner join # Tcustttemp1 a on dj . ROUTECODE = a . ROUTECODE and a . OPCODE = dj . OPCODE and optionalop = ' 检 验 工 序 '
inner join icsmo b with ( nolock ) on dj . MOCODE = b . MOCODE and dj . MOSEQ = b . MOSEQ
inner join ICSMO2user d with ( nolock ) on b . mocode = d . mocode and b . moseq = d . moseq and d . opcode = dj . OPCODE
where MONTH ( d . MTIME ) = MONTH ( GETDATE ( ) ) and YEAR ( ( d . MTIME ) ) = YEAR ( GETDATE ( ) )
union
select c . molotCode [ 销 售 车 号 ] - - , d . LOTNO [ 产 品 跟 踪 单 ] , d . OPCODE [ 工 序 代 码 ]
from
( select * from ICSITEMROUTE2OP with ( nolock ) where optionalop = ' 检 验 工 序 ' and routecode in (
select DISTINCT routecode from ICSITEMROUTE2OP with ( nolock ) GROUP BY routecode HAVING count ( * ) = 1 ) ) a - - 查 询 只 有 一 道 工 序 的 工 艺 路 线
inner JOIN ICSMO2ROUTE b with ( nolock ) on a . routeid = b . routeid
inner join ICSMO c with ( nolock ) on c . id = b . moid
inner join ICSMO2user d with ( nolock ) on c . mocode = d . mocode and c . moseq = d . moseq
inner join ICSITEMROUTE2OPLot lot with ( nolock ) on lot . itemcode = a . ITEMCODE and b . ROUTECODE = lot . ROUTECODE and lot . OPCODE = d . opcode
//--1、待检验数据 待检车辆
// select count(1) Qty into #Tcustt_TOCKQty
// from (
//select b.molotCode [销售车号] -- , dj.LOTNO [产品跟踪单], dj.OPCODE [工序代码]
//from #TcusttDJ dj
//inner join #Tcustttemp1 a on dj.ROUTECODE = a.ROUTECODE and a.OPCODE = dj.OPCODE and optionalop ='检验工序'
//inner join icsmo b with(nolock) on dj.MOCODE = b.MOCODE and dj.MOSEQ = b.MOSEQ
//inner join ICSMO2user d with(nolock) on b.mocode = d.mocode and b.moseq = d.moseq and d.opcode = dj.OPCODE
//where MONTH(d.MTIME)=MONTH(GETDATE()) and YEAR((d.MTIME)) = YEAR(GETDATE())
//union
//select c.molotCode [销售车号] --, d.LOTNO [产品跟踪单], d.OPCODE [工序代码]
//from
//(select * from ICSITEMROUTE2OP with(nolock) where optionalop ='检验工序' and routecode in(
//select DISTINCT routecode from ICSITEMROUTE2OP with(nolock) GROUP BY routecode HAVING count(*) = 1 )) a --查询只有一道工序的工艺路线
//inner JOIN ICSMO2ROUTE b with(nolock) on a.routeid = b.routeid
//inner join ICSMO c with(nolock) on c.id = b.moid
//inner join ICSMO2user d with(nolock) on c.mocode = d.mocode and c.moseq = d.moseq
//inner join ICSITEMROUTE2OPLot lot with(nolock) on lot.itemcode = a.ITEMCODE and b.ROUTECODE = lot.ROUTECODE and lot.OPCODE = d.opcode
where not exists ( select 1 from ICSLOTONWIP wip with ( nolock ) where wip . lotno = d . LOTNO and wip . opcode = d . OPCODE and wip . actionresult = ' COLLECT_END ' and MONTH ( d . MTIME ) = MONTH ( GETDATE ( ) ) and YEAR ( ( d . MTIME ) ) = YEAR ( GETDATE ( ) ) )
//where not exists (select 1 from ICSLOTONWIP wip with(nolock) where wip.lotno = d.LOTNO and wip.opcode =d.OPCODE and wip.actionresult ='COLLECT_END' and MONTH(d.MTIME)=MONTH(GETDATE()) and YEAR((d.MTIME)) = YEAR(GETDATE()))
) jj
//) jj
select a . ITEMCODE , a . ROUTECODE , a . OPCODE , a . OPType AS OPTIONALOP , a . controlMethod , a . OPControlSeq , b . LOTNO ,
isnull ( b . ACTIONRESULT , '~' ) as ACTIONRESULT , b . MOCODE , b . MOSEQ , d . molotcode , b . BeginTime , b . userCodeEnd , b . endtime into # temp1
from ICSITEMROUTE2OPLot a
left join icslotonwip b on a . ITEMCODE = b . ITEMCODE and a . ROUTECODE = b . ROUTECODE and a . OPCODE = b . OPCODE
inner join ( SELECT a . ITEMCODE , a . ROUTECODE , count ( b . ACTIONRESULT ) as 汇 总
from ICSITEMROUTE2OPLot a
left join icslotonwip b on a . ITEMCODE = b . ITEMCODE and a . ROUTECODE = b . ROUTECODE and a . OPCODE = b . OPCODE
WHERE b . ACTIONRESULT is not null
GROUP BY a . ITEMCODE , a . ROUTECODE
HAVING COUNT ( b . ACTIONRESULT ) > 0 ) c on a . ITEMCODE = c . ITEMCODE and a . ROUTECODE = c . ROUTECODE
left join icsmo d on d . MOCODE = b . MOCODE and b . SEQ = d . MOSEQ
inner join ICSMO2user e on d . mocode = e . mocode and e . moseq = d . moseq and year ( e . mtime ) = year ( GETDATE ( ) ) and month ( e . mtime ) = month ( GETDATE ( ) )
order by ITEMCODE , OPControlSeq
SELECT ITEMCODE , ROUTECODE , ACTIONRESULT INTO # FILTER FROM ICSLOTONWIP WHERE ACTIONRESULT = ' COLLECT_BEGIN '
- - 找 出 待 检 的 工 序
select ITEMCODE , a . ROUTECODE , OPCODE , c . MOCODE , c . MOSEQ , c . LOTNO into # DJ from # temp1 a
inner join
( select min ( OPControlSeq ) OPControlSeq , ROUTECODE from # temp1 where OPTIONALOP = ' 检 验 工 序 ' and LOTNO is null
and ROUTECODE in
( SELECT Ta . ROUTECODE
FROM
(
SELECT t1 . OPControlSeq , t1 . ROUTECODE
FROM
(
SELECT min ( OPControlSeq ) AS OPControlSeq , ROUTECODE
FROM # temp1
WHERE ACTIONRESULT = '~' AND LOTNO IS NULL
GROUP BY ROUTECODE
) t1
INNER JOIN
(
SELECT MIN ( OPControlSeq ) AS OPControlSeq , ROUTECODE
FROM # temp1
WHERE OPTIONALOP = ' 检 验 工 序 ' AND LOTNO IS NULL
GROUP BY ROUTECODE
) b
ON t1 . ROUTECODE = b . ROUTECODE AND b . OPControlSeq = t1 . OPControlSeq
) Ta )
GROUP BY ROUTECODE ) b
on a . ROUTECODE = b . ROUTECODE and a . OPControlSeq = b . OPControlSeq
inner join ( select distinct mocode , MOSEQ , ROUTECODE , LOTNO from icslotonwip ) c
on a . ROUTECODE = c . ROUTECODE
where
not EXISTS ( select 1 from # filter f
where f . ITEMCODE = a . ITEMCODE and f . ROUTECODE = a . ROUTECODE )
select itemcode , routecode , max ( endtime ) endtime into # yjCheck from # temp1 where ACTIONRESULT = ' COLLECT_END ' group by itemcode , routecode
select t1 . ROUTECODE , t1 . opcode , t1 . endtime , user1 . Username as name
into # yjCheck1
from
# yjCheck ck
LEFT JOIN # temp1 t1 on ck . ROUTECODE = t1 . ROUTECODE and ck . itemcode = t1 . itemcode and ck . endtime = t1 . endtime
left join Sys_User user1 on user1 . usercode = t1 . UserCodeEnd
- - 将 数 据 拼 接 成 在 检 和 待 检 两 部 分
select count ( 1 ) Qty into # Tcustt_TOCKQty
from (
select distinct b . molotCode [ 销 售 车 号 ]
from # DJ dj
inner join # temp1 a on dj . ROUTECODE = a . ROUTECODE and a . OPCODE = dj . OPCODE and optionalop = ' 检 验 工 序 '
inner join icsmo b on dj . MOCODE = b . MOCODE and dj . MOSEQ = b . MOSEQ
inner join ICSMO2user d on b . mocode = d . mocode and b . moseq = d . moseq and d . opcode = dj . OPCODE
inner join ICSSO so on SO . socode = b . molotCode
left join ICSOP op on dj . opcode = OP . opcode
left join # yjCheck1 ck on ck . routecode = a . routecode
left join ICSITEMROUTE2OPLot lot on b . itemcode = lot . ITEMCODE and dj . ROUTECODE = lot . ROUTECODE and lot . OPCODE = dj . opcode
left join ICSINVENTORY e on a . ITEMCODE = e . INVCODE
where year ( d . MTIME ) = year ( GETDATE ( ) ) and month ( d . MTIME ) = month ( GETDATE ( ) ) and
union All
select distinct c . molotCode [ 销 售 车 号 ] from
( select * from ICSITEMROUTE2OP where optionalop = ' 检 验 工 序 ' and routecode in (
select DISTINCT routecode from ICSITEMROUTE2OP GROUP BY routecode HAVING count ( * ) = 1 ) ) a - - 查 询 只 有 一 道 工 序 的 工 艺 路 线
inner JOIN ICSMO2ROUTE b on a . routeid = b . routeid
inner join ICSMO c on c . id = b . moid
inner join ICSMO2user d on c . mocode = d . mocode and c . moseq = d . moseq
inner join ICSITEMROUTE2OPLot lot on lot . itemcode = a . ITEMCODE and b . ROUTECODE = lot . ROUTECODE and lot . OPCODE = d . opcode
inner join ICSINVENTORY e on c . ITEMCODE = e . invCode
left join ICSSO so on SO . socode = c . molotCode
left join ICSOP op on d . opcode = OP . opcode
where year ( d . MTIME ) = year ( GETDATE ( ) ) and month ( d . MTIME ) = month ( GETDATE ( ) ) and not exists ( select 1 from ICSLOTONWIP wip where wip . lotno = d . LOTNO and wip . opcode = d . OPCODE and wip . actionresult = ' COLLECT_END ' )
) jj
- - 1 、 已 检 验 数 据 已 检 车 辆
- - 1 、 已 检 验 数 据 已 检 车 辆