- 打卡等级:无名新人
- 打卡总天数:1
- 打卡月天数:0
- 打卡总奖励:3
- 最近打卡:2024-10-23 18:41:09
|
楼主 |
发表于 2021-7-15 13:23:01
|
显示全部楼层
- BOM查询
- --增加了数量
- DECLARE @partid INT;
- SELECT @partid = 225323;
- WITH parts (pbom, pid, cbom, cid, lvl, seq, sortseq, fvflag, pqty, cqty, baseqtyn, baseqtyd)
- AS (SELECT NULL,
- p.ParentId,
- p.BomId,
- p.ParentId,
- 0,
- 0,
- 0,
- 1,
- CAST(1.0 AS DECIMAL(20, 10)),
- 1,
- 1,
- 1
- FROM dbo.bom_parent AS p
- JOIN dbo.bom_bom AS b
- ON b.BomId = p.BomId
- WHERE b.VersionEffDate <= GETDATE()
- AND b.VersionEndDate > GETDATE()
- AND b.BomType = 1
- UNION
- SELECT p.BomId,
- p.ParentId,
- cb.BomId,
- c.ComponentId,
- 0 AS lvl,
- CAST(ROW_NUMBER() OVER (PARTITION BY c.BomId ORDER BY c.SortSeq) AS INT) AS seq,
- c.SortSeq,
- c.FVFlag,
- CAST(1.0 AS DECIMAL(20, 10)),
- c.BaseQtyN / c.BaseQtyD,
- c.BaseQtyN,
- c.BaseQtyD
- FROM dbo.bom_parent AS p
- JOIN dbo.bom_bom AS b
- ON b.BomId = p.BomId
- JOIN dbo.bom_opcomponent AS c
- ON c.BomId = p.BomId
- LEFT JOIN dbo.bom_parent AS cb
- ON c.ComponentId = cb.ParentId
- LEFT JOIN dbo.bom_bom AS bc
- ON bc.BomId = cb.BomId
- --LEFT JOIN dbo.bom_opcomponentopt bo ON c.OptionsId = bo.OptionsId
- WHERE b.VersionEffDate <= GETDATE()
- AND b.VersionEndDate > GETDATE()
- AND
- (
- (
- bc.VersionEffDate <= GETDATE()
- AND bc.VersionEndDate > GETDATE()
- AND bc.BomType = 1
- )
- OR bc.BomId IS NULL
- )),
- bom
- AS (SELECT parts.pid AS ancestor,
- parts.pbom,
- parts.pid,
- parts.cbom,
- parts.cid,
- parts.lvl,
- parts.seq,
- parts.sortseq,
- CAST('01' AS NVARCHAR(50)) AS pseq,
- parts.fvflag,
- CAST(parts.pqty AS DECIMAL(20, 10)) AS pqty,
- CASE parts.fvflag
- WHEN 0 THEN
- parts.cqty
- ELSE
- parts.pqty * parts.cqty
- END AS cqty,
- parts.baseqtyn,
- parts.baseqtyd
- FROM parts
- WHERE parts.pbom IS NULL
- AND parts.pid = @partid
- UNION ALL
- SELECT p.ancestor,
- c.pbom,
- c.pid,
- c.cbom,
- c.cid,
- p.lvl + 1,
- c.seq,
- c.sortseq,
- CAST(p.pseq + '.' + RIGHT('00' + CAST(c.seq AS NVARCHAR(50)), 2) AS NVARCHAR(50)),
- c.fvflag,
- CAST(p.cqty AS DECIMAL(20, 10)),
- CASE c.fvflag
- WHEN 0 THEN
- c.cqty
- ELSE
- p.cqty * c.cqty
- END,
- c.baseqtyn,
- c.baseqtyd
- FROM parts AS c
- JOIN bom AS p
- ON p.cbom = c.pbom)
- SELECT *
- FROM bom AS b
- ORDER BY b.pseq
- OPTION (HASH JOIN, MAXRECURSION 10);
复制代码
|
|