|
|
发表于 2011/11/16 08:57:31
|
显示全部楼层
四班自己带的方法:
create procedure usp_ReportSdal
@anReportInstanceID int
,@afmultiplier float
,@DeleteTempData varchar(1) = 'Y' -- 'Y' means delete the temp data
as
select im.ItemNumber
,case
when im.MakeBuyCode = 'M'
then im.Planner
else im.Buyer
end as PlannerBuyer -- two type, 'C' and 'S'
,imd.ReplanCode
,im.LastPeriodReviewDate ReplanDate
,im.ItemDescription
,im.ItemUM
,im.ItemRevision
,im.MakeBuyCode
,im.ItemType
,im.ItemStatus
,im.OrdERPolicy
,im.IsInspectionRequired
,im.DecimalPrecision
,imd.OnHandQuantity
,case
when rsd.SupplyDemandType = 'D' or rsd.SupplyDemandType = 'S'
then convert(char(1),rsd.StartForecastPeriod)
else ''
end StartForecastPeriod
,case
when rsd.SupplyDemandType = 'I'
then null
else rsd.RequiredDate
end RequiredDate
,case
when rsd.SupplyDemandType = 'D'
then rsd.GrossRequiredFlag
else null
end GrossRequiredFlag
,case rsd.PlannedOrderQuantity
when 0
then case rsd.SupplyDemandType
when 'D'
then rsd.GrossRequiredQuantity * @afmultiplier
else null
end
else null
end GrossRequiredQuantity
,case rsd.PlannedOrderQuantity
when 0
then case
when rsd.SupplyDemandType = 'S' or rsd.SupplyDemandType = 'I'
then rsd.ScheduledReceiptQuantity * @afmultiplier
else null
end
else null
end ScheduledReceiptQuantity
,rsd.ProjectedAvailableQuantity * @afmultiplier ProjectedAvailableQuantity
,case rsd.PlannedOrderQuantity
when 0 then null
else rsd.PlannedOrderQuantity * @afmultiplier
end PlannedOrderQuantity
,case
when rsd.SupplyDemandType = 'P'
then 'P'--'CUSTOM PROD INV'
else rsd.PeggingInformation
end PeggingType
,rsd.MessageCount Messages
,rsd.SupplyDemandKey SuperKey
from FS_Item im (readuncommitted)
join FS_ItemData imd (readuncommitted) on (im.ItemKey = imd.ItemKey)
left join FSDBBJTemp.dbo.FS_ReportSDASupplyDemand rsd (readuncommitted) on im.ItemKey = rsd.ItemKey
where rsd.ReportInstanceKey =@anReportInstanceID
order by ItemNumber, RequiredDate, TopLevelDemandKey, SupplyDemandType desc, rsd.SupplyDemandKey
-- delete Instance from FS_ReportSDASupplyDemand and FS_ReportSDASupplyDemand table
-- the 3rd parameter for usp_ReportDeleteInstance is for SequenceNo,we do not need here
exec usp_ReportDeleteInstance @anReportInstanceID, null , null,@DeleteTempData
return |
|