金蝶K3 SQL报表系列-生产在线材料查询

1、创建存储过程,代码如下:

 

 
  1. create procedure [dbo].[rk_sp_wip_status]

  2. @enddate datetime

  3. as

  4.  
  5.  
  6. --declare @enddate datetime

  7.  
  8. --set @enddate='2012-06-30'

  9.  
  10. select

  11. u1.FBillNo 任务单号,

  12. u1.FCheckDate 下单日期,

  13. case when u1.FStatus=0 then '计划' when u1.FStatus=3 then '结案' when u1.FStatus in (1,2) then '下达' else '' end as 状态,

  14. u11.FNumber 产品代码,

  15. u11.FName 产品名称,

  16. u11.FModel 产品规格,

  17. u1.FQty 生产数量,

  18. t3.FBegStockInQty 截止入库数量,

  19. t3.FEndStockInQty 期后入库数量,

  20. t21.FNumber 材料代码,

  21. t21.FName 材料名称,

  22. t21.FModel 材料规格,

  23. t22.Fname 领料类型,

  24. t23.Fname 发料仓库,

  25. t2.FqtyScrap 标准用量,

  26. case when t2.FMaterielType=376 then -t2.FQtyMust else t2.FQtyMust end 需发料数量,

  27. t2.FDiscardQty 报废数量,

  28. t4.FBegStockOutQty 截止领料数量,

  29. t4.FEndStockOutQty 期后领料数量,

  30. t5.FBegScrapQty 报废数量,

  31. t5.FEndScrapQty 期末报废数量,

  32. isnull(t4.FBegStockOutQty,0)-((case when t2.FMaterielType=376 then -t2.FQtyMust else t2.FQtyMust end)/u1.FQty)*isnull(t3.FBegStockInQty,0)-isnull(t5.FBegScrapQty,0) 在线数量

  33. from icmo u1

  34. inner join t_icitem u11 on u11.FItemID=u1.FItemID

  35. inner join PPBOM t1 on u1.FInterID=t1.FICMOInterID

  36. inner join PPBOMEntry t2 on t1.FInterID=t2.FInterID

  37. inner join t_ICItem t21 on t21.FItemID=t2.FItemID

  38. left join t_submessage t22 on t22.Finterid=t2.FMaterielType

  39. left join t_stock t23 on t23.Fitemid=t2.Fstockid

  40. left join

  41. (

  42. select

  43. t1.FICMOInterID,

  44. sum(case when u1.FDate<@enddate then t1.FQty else 0 end) as FBegStockInQty,

  45. sum(case when u1.FDate>=@enddate then t1.FQty else 0 end) as FEndStockInQty

  46. from ICStockBill u1

  47. inner join ICStockBillEntry t1 on u1.FInterID=t1.FInterID

  48. where u1.FCancellation=0 and u1.FTranType=2

  49. group by FICMOInterID

  50. ) t3 on t3.FICMOInterID=u1.FInterID

  51. left join

  52. (

  53. select

  54. t1.FICMOInterID,

  55. t1.FPPBomEntryID,

  56. sum(case when u1.FDate<@enddate then t1.FQty else 0 end) as FBegStockOutQty,

  57. sum(case when u1.FDate>=@enddate then t1.FQty else 0 end) as FEndStockOutQty

  58. from ICStockBill u1

  59. inner join ICStockBillEntry t1 on u1.FInterID=t1.FInterID

  60. where u1.FCancellation=0 and u1.FTranType=24

  61. group by FICMOInterID,t1.FPPBomEntryID

  62. ) t4 on t4.FICMOInterID=t2.FICMOInterID and t4.FPPBomEntryID=t2.FEntryID

  63. left join

  64. (

  65. select

  66. t4_1.Fsourceinterid,

  67. sum(case when t4_2.FDate<@enddate then t4_1.FQty else 0 end) as FBegScrapQty,

  68. sum(case when t4_2.FDate>=@enddate then t4_1.FQty else 0 end) as FEndScrapQty,

  69. t4_1.FSourceEntryid,

  70. t4_1.FSourceTranType

  71. from

  72. ICItemScrapEntry t4_1

  73. inner join ICItemScrap t4_2 on t4_1.finterid=t4_2.finterid

  74. where t4_2.Fdate<@enddate and t4_2.Fstatus=1

  75. group by t4_1.Fsourceinterid,t4_1.FSourceEntryid,t4_1.FSourceTranType

  76.  
  77.  
  78.  
  79. ) t5 on t5.FSourceInterid=t1.FICMOInterid and t5.FSourceEntryid=t2.FEntryID

  80. where

  81. (

  82. (

  83. (

  84. u1.FCloseDate>=@enddate

  85. or u1.FInterID in (

  86. select FICMOInterID from ICStockBillEntry u1

  87. inner join ICStockBill t1 on u1.FInterID=t1.FInterID

  88. where t1.FCancellation=0

  89. and t1.FDate>=@enddate)

  90. )

  91. and u1.FStatus=3

  92. )

  93. or u1.FStatus in (1,2)

  94. ) and u1.FCheckDate<@enddate

  95. order by u1.FBillNo

 

 

2、K3调用存储视图:

 

exec rk_sp_wip_status '########'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值