|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
本帖最后由 janse_wang 于 2016-6-20 12:52 编辑
DECLARE @STRCN VARCHAR(8000)
SELECT @STRCN=ISNULL(@STRCN+',','')+ K.[母件编码] FROM
(select
a.BomId as 'BOMID',
c.InvCode as '母件编码',d.cInvName as '母件名称' ,
j.InvCode as '子件编码',h.cInvName as '子件名称',
d.cInvStd as '子件规格',e.cComUnitName as '计量单位',
SUM(F.BaseQtyD) as '基本用量' ,CompScrap as '子件损耗率',
EffBegDate as '子件生效日',EffEndDate as '子件失效日'
from bom_bom as a
join bom_parent as b on a.BomId=b.BomId
join bom_opcomponent as f on b.BomId=f.BomId
join bas_part as c on b.ParentId=c.PartId
join bas_part as j on f.componentId=j.PartId
join Inventory as d on c.InvCode=d.cInvCode
join Inventory as h on j.InvCode=h.cInvCode
join ComputationUnit as e ON h.cComUnitCode =e.cComUnitCode
GROUP BY
a.BomId,
c.InvCode,d.cInvName,
j.InvCode,h.cInvName,
d.cInvStd ,e.cComUnitName,CompScrap,
EffBegDate,EffEndDate) as k
GROUP BY K.[母件编码]
--PRINT(@STRCN)
DECLARE @SQLSTR VARCHAR(8000)
SET @SQLSTR='
SELECT * FROM
(
select
c.InvCode as '母件编码',
j.InvCode as '子件编码',
SUM(F.BaseQtyD) as '基本用量'
from bom_bom as a
join bom_parent as b on a.BomId=b.BomId
join bom_opcomponent as f on b.BomId=f.BomId
join bas_part as c on b.ParentId=c.PartId
join bas_part as j on f.componentId=j.PartId
join Inventory as d on c.InvCode=d.cInvCode
join Inventory as h on j.InvCode=h.cInvCode
join ComputationUnit as e ON h.cComUnitCode =e.cComUnitCode
GROUP BY
c.InvCode,
j.InvCode,
) AS T
PIVOT(MAX(T.[基本用量])
FOR T.[母件编码] IN ( '+@STRCN+' ) ) AS W'
--PRINT(@SQLSTR)
EXEC(@SQLSTR)
|
|