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

  1. create procedure [dbo].[rk_sp_stock_Age]

  2. @paraYear int,

  3. @parePeriod int

  4. as

  5. declare @year int

  6. declare @period int

  7. declare @Fdate datetime

  8. --declare @paraYear int

  9. --declare @parePeriod int

  10. --set @paraYear=2013

  11. --set @parePeriod=10

  12. if @parePeriod=12

  13. begin

  14. set @year=@paraYear+1

  15. set @period=1

  16. end

  17. else

  18. begin

  19. set @year=@paraYear

  20. set @period=@parePeriod+1

  21. end

  22. set @Fdate=convert(datetime,convert(nvarchar(20),@year)+'-'+convert(nvarchar(20),@period)+'-01')-1

  23. select

  24. b.FNumber 物料代码,

  25. b.FName 物料名称,

  26. b.FModel 规格型号,

  27. a.FBegQty/c.Fcoefficient 期末数量,

  28. c.Fname 单位,

  29. a.FBegBal 期末金额,

  30. a.FQty1/c.Fcoefficient [0-29天+数量] ,

  31. a.FAmount1 [0-29天+金额],

  32. a.FQty2/c.Fcoefficient [30-59天+数量],

  33. a.FAmount2 [30-59天+金额],

  34. a.FQty3/c.Fcoefficient [60-89天+数量],

  35. a.FAmount3 [60-89天+金额],

  36. a.FQty4/c.Fcoefficient [90-179天+数量],

  37. a.FAmount4 [90-179天+金额],

  38. a.FQty5/c.Fcoefficient [180-359天+数量],

  39. a.FAmount5 [180-359天+金额],

  40. a.FQty6/c.Fcoefficient [360-719天+数量],

  41. a.FAmount6 [360-719天+金额],

  42. a.FQty7/c.Fcoefficient [720天以上+数量],

  43. a.FAmount7 as[720天以上+金额]

  44. from

  45. (

  46. select

  47. u1.FItemID,

  48. u1.FBegQty,

  49. u1.FBegBal,

  50. u1.FPrice,

  51. case when isnull (u1.FBegQty,0)>=isnull (t1.FQty1,0) then isnull (t1.FQty1,0) else isnull (u1.FBegQty,0) end as FQty1,

  52. round(case when isnull (u1.FBegQty,0)>=isnull (t1.FQty1,0) then isnull (t1.FQty1,0) else isnull (u1.FBegQty,0) end*u1.FPrice,2) as FAmount1,

  53. case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0) then isnull (t1.FQty2,0)

  54. else case when isnull (u1.FBegQty,0)>=isnull (t1.FQty1,0) then isnull (u1.FBegQty,0)-isnull (t1.FQty1,0)

  55. else 0 end

  56. end as FQty2,

  57. round(case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0) then isnull (t1.FQty2,0)

  58. else

  59. case when isnull (u1.FBegQty,0)>=isnull (t1.FQty1,0) then isnull (u1.FBegQty,0)-isnull (t1.FQty1,0)

  60. else 0 end

  61. end*u1.FPrice,2) as FAmount2,

  62. case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0) then isnull (t1.FQty3,0)

  63. else

  64. case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0) then isnull (u1.FBegQty,0)-isnull (t1.FQty1,0)-isnull (t1.FQty2,0) else 0 end

  65. end as FQty3,

  66. round(case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0) then isnull (t1.FQty3,0)

  67. else

  68. case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0) then isnull (u1.FBegQty,0)-isnull (t1.FQty1,0)-isnull (t1.FQty2,0) else 0 end

  69. end*u1.FPrice,2) as FAmount3,

  70. case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull (t1.FQty4,0) then isnull (t1.FQty4,0)

  71. else case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0) then isnull (u1.FBegQty,0)-isnull (t1.FQty1,0)-isnull (t1.FQty2,0)-isnull (t1.FQty3,0) else 0 end

  72. end as FQty4,

  73. round(case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull (t1.FQty4,0) then isnull (t1.FQty4,0)

  74. else case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0) then isnull (u1.FBegQty,0)-isnull (t1.FQty1,0)-isnull (t1.FQty2,0)-isnull (t1.FQty3,0) else 0 end

  75. end*u1.FPrice,2) as FAmount4,

  76. case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull (t1.FQty4,0)+isnull (t1.FQty5,0) then isnull (t1.FQty5,0)

  77. else case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull (t1.FQty4,0) then isnull (u1.FBegQty,0)-isnull (t1.FQty1,0)-isnull (t1.FQty2,0)-isnull (t1.FQty3,0)-isnull (t1.FQty4,0) else 0 end

  78. end as FQty5,

  79. round(case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull (FQty4,0)+isnull (t1.FQty5,0) then isnull (t1.FQty5,0)

  80. else

  81. case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull (t1.FQty4,0) then isnull (u1.FBegQty,0)-isnull (t1.FQty1,0)-isnull (t1.FQty2,0)-isnull (t1.FQty3,0)-isnull (t1.FQty4,0) else 0 end

  82. end*u1.FPrice,2) as FAmount5,

  83. case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull (t1.FQty4,0)+isnull (t1.FQty5,0)+isnull (t1.FQty6,0) then isnull (t1.FQty6,0)

  84. else

  85. case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull (t1.FQty4,0)+isnull (t1.FQty5,0)

  86. then isnull (u1.FBegQty,0)-isnull (t1.FQty1,0)-isnull (t1.FQty2,0)-isnull (t1.FQty3,0)-isnull (t1.FQty4,0)-isnull (t1.FQty5,0) else 0 end

  87. end as FQty6,

  88. round((case when isnull(u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull (t1.FQty4,0)+isnull (t1.FQty5,0)+isnull (t1.FQty6,0)then isnull (t1.FQty6,0)

  89. else

  90. case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull (t1.FQty4,0)+isnull (t1.FQty5,0)

  91. then isnull (u1.FBegQty,0)-isnull (t1.FQty1,0)-isnull (t1.FQty2,0)-isnull (t1.FQty3,0)-isnull (t1.FQty4,0)-isnull (t1.FQty5,0)

  92. else 0

  93. end

  94. end)*u1.FPrice,2) as FAmount6,

  95. case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull (FQty4,0)+isnull (t1.FQty5,0)+isnull (t1.FQty6,0)+isnull (t1.FQty7,0)

  96. then isnull (u1.FBegQty,0)-(isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull (FQty4,0)+isnull (t1.FQty5,0)+isnull (t1.FQty6,0))

  97. else case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull (t1.FQty4,0)+isnull (t1.FQty5,0)+isnull (t1.FQty6,0)

  98. then isnull (u1.FBegQty,0)-isnull (t1.FQty1,0)-isnull (t1.FQty2,0)-isnull (t1.FQty3,0)-isnull (t1.FQty4,0)-isnull (t1.FQty5,0)-isnull (t1.FQty6,0)

  99. else 0 end

  100. end as FQty7,

  101. round(case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull(t1.FQty4,0)+isnull (t1.FQty5,0)+isnull (t1.FQty6,0)+isnull (FQty7,0)

  102. then isnull (u1.FBegQty,0)-(isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull (t1.FQty4,0)+isnull (t1.FQty5,0)+isnull (t1.FQty6,0))

  103. else case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0)+isnull(t1.FQty4,0)+isnull (t1.FQty5,0)+isnull (t1.FQty6,0)

  104. then isnull (u1.FBegQty,0)-isnull (t1.FQty1,0)-isnull (t1.FQty2,0)-isnull (t1.FQty3,0)-isnull (t1.FQty4,0)-isnull (t1.FQty5,0)-isnull (t1.FQty6,0)

  105. else 0 end

  106. end*u1.FPrice,2) as FAmount7

  107. from (

  108. select FItemID,sum(FBegQty) as FBegQty,sum(FBegBal) FBegBal,case when sum(FBegQty)=0 then 0 else sum(FBegBal)/sum(FBegQty) end as FPrice from ICbal where FYear=@year and FPeriod=@period group by FItemID

  109. ) u1

  110. left join

  111. (

  112. select t1.Fitemid,

  113. sum((Case When t5.FDate>=Convert(DateTime,Convert(Varchar,DATEADD(dd,-29,@Fdate),101)) And t5.FDate<=Convert(DateTime,Convert(Varchar,DATEADD(dd,-0,@Fdate),101)) Then t6.FQty*t5.FRob Else 0 End)) As FQty1,

  114. sum((Case When t5.FDate>=Convert(DateTime,Convert(Varchar,DATEADD(dd,-59,@Fdate),101)) And t5.FDate<=Convert(DateTime,Convert(Varchar,DATEADD(dd,-30,@Fdate),101)) Then t6.FQty*t5.FRob Else 0 End)) As FQty2,

  115. sum((Case When t5.FDate>=Convert(DateTime,Convert(Varchar,DATEADD(dd,-89,@Fdate),101)) And t5.FDate<=Convert(DateTime,Convert(Varchar,DATEADD(dd,-60,@Fdate),101)) Then t6.FQty*t5.FRob Else 0 End)) As FQty3,

  116. sum((Case When t5.FDate>=Convert(DateTime,Convert(Varchar,DATEADD(dd,-179,@Fdate),101)) And t5.FDate<=Convert(DateTime,Convert(Varchar,DATEADD(dd,-90,@Fdate),101)) Then t6.FQty*t5.FRob Else 0 End)) As FQty4,

  117. sum((Case When t5.FDate>=Convert(DateTime,Convert(Varchar,DATEADD(dd,-359,@Fdate),101)) And t5.FDate<=Convert(DateTime,Convert(Varchar,DATEADD(dd,-180,@Fdate),101)) Then t6.FQty*t5.FRob Else 0 End)) As FQty5,

  118. sum((Case When t5.FDate>=Convert(DateTime,Convert(Varchar,DATEADD(dd,-719,@Fdate),101)) And t5.FDate<=Convert(DateTime,Convert(Varchar,DATEADD(dd,-360,@Fdate),101)) Then t6.FQty*t5.FRob Else 0 End)) As FQty6,

  119. sum((Case When t5.FDate>=Convert(DateTime,Convert(Varchar,DATEADD(dd,-720,@Fdate),101)) And t5.FDate<=Convert(DateTime,Convert(Varchar,DATEADD(dd,-720,@Fdate),101)) Then t6.FQty*t5.FRob Else 0 End)) As FQty7

  120. From t_ICItem t1

  121. Join ICStockBill t5 On (t5.FStatus > 0 Or (t5.FUpStockWhenSave > 0 And t5.FCancellation <1 ))

  122. Join ICStockBillEntry t6 On t5.FInterID=t6.FInterID

  123. Where t1.FItemID = t6.FItemID

  124. And ((t5.FTrantype In (1,2,5,10,40) And t5.FRob =1) Or (t5.FTrantype In(21,24,28,29) And t5.FRob=-1))

  125. AND (NOT (t5.FTrantype In (1) AND t5.FPOMode = 36681 ))

  126. and t5.Fdate<=@Fdate and t5.FCancellation=0

  127. group by t1.FItemID

  128. ) t1 on u1.FItemID=t1.FItemID

  129. ) a

  130. inner join t_ICItem b on a.FItemID=b.FItemID

  131. inner join t_Measureunit c on c.Fitemid=b.FStoreunitid

  132. order by b.Fnumber

2、K3查询分析工具,新增sql关键字:

@Period@  数字型  手工录入  无

3、K3查询分析工具调用存储过程:

exec rk_sp_stock_Age @Year@,@Period@

金蝶K3 SQL报表系列-库存账龄分析相关推荐

  1. 金蝶K3 SQL报表系列-委外核销检查表

    1.创建存储过程:sp_ICStockBill_Check create procedure [dbo].[sp_ICStockBill_Check] as set nocount on declar ...

  2. 金蝶K3 SQL报表系列-供应商应付/预付账款明细表

    1.创建供应商应付预付账款明细总表存储过程:sp_getAccount_detail,代码如下: create procedure [dbo].[sp_getAccount_detail]@Start ...

  3. 金蝶K3 SQL报表系列-BOM成本汇总表

    1.创建供应商维护价格视图z_view_SupplyRatePrice,代码如下: create view [dbo].[z_view_SupplyRatePrice] as select u1.*, ...

  4. 金蝶K3 SQL报表系列-客户科目余额表(可用于生成客户保证金查询报表等)

    select k3.FNumber 客户代码, k3.FName 客户名称, k2.FNumber 科目代码, k2.FFullName 科目名称, k.FEndBalance 余额from (sel ...

  5. 金蝶K3 SQL报表系列-供应商科目余额表

    创建存储过程:exec sp_get_supply_balance 代码如下: create procedure [dbo].[sp_get_supply_balance] as set nocoun ...

  6. 金蝶K3 SQL报表系列-委外未勾稽明细表金蝶K3 SQL报表系列-委外未勾稽明细表

    select u1.FBillNo 单据编号, u1.FDate 日期, t3.FNumber as 供应商代码, t3.FName as 供应商, t4.FNumber 物料代码, t4.FName ...

  7. 金蝶K3 SQL报表系列-委外未勾稽明细表

    select u1.FBillNo 单据编号, u1.FDate 日期, t3.FNumber as 供应商代码, t3.FName as 供应商, t4.FNumber 物料代码, t4.FName ...

  8. 金蝶K3直接SQL报表实现动态行转列报表

    我们知道,在BOS开发中,想实现动态行转列报表,可以使用交叉分析表来实现,但交叉分析表不太灵活,比如当动态列中有需要复杂的逻辑运算来实现时就无能为力了,下面介绍使用直接SQL报表来实现,也许能给你一点 ...

  9. Excel+MSSQL开发金蝶K3欠料报表

    将K3所有订单需求.MRP运算.库存及在途数据等数据整体展示,适合计划部门根据报表数据统筹考量物料供给情况,特制作此报表及Excel集成工具,以减少手工汇总统计的工作量. 本代码适用于金蝶K3 WIS ...

最新文章

  1. A - 小C语言--词法分析程序
  2. WindowsServer2012 R2 64位中文标准版(IIS8.5)下手动搭建PHP环境详细图文教程(二)安装IIS8.5...
  3. scala中:: , +:, :+, :::, +++的区别
  4. 我是一个*** (十三)
  5. socket.io 消息发送
  6. Eclipse SVN插件Subclipse和Subversive简介
  7. Windows中的用户和组以及用户密码破解
  8. Codevs_P1907HDU_P1565 方格取数3(最大流)
  9. df满足条件的值修改_python – 如何根据其他列中的条件将pandas df列中的多个值更改为np.nan?...
  10. 全新的服务器debian/ubuntu---校准时间、更新apt,设置ssh远程访问
  11. 怎么恢复计算机文件查看方式,win7电脑打开方式怎么还原?win7电脑还原打开方式的方法...
  12. layui时间日期控件laydate设置默认值,并且结束时间大于开始时间
  13. The nested type test2 cannot hide an enclosing type
  14. 开源办公OA开发平台使用说明:用车管理应用
  15. 【NetWorkX实例(4)】Football数据集
  16. JAVA高考加油,2017年高考加油祝福语
  17. 红外热成像传感器介绍
  18. MATLB|基于燃料电池混合动力汽车双层凸优化
  19. Android Studio 播放bibi声音
  20. fzyzojP3618 -- [校内训练-互测20180412]士兵的游戏

热门文章

  1. Labview通讯三菱Q PLC,Labvew TCP通讯三菱PLC ,MCTCP,三菱PLC连接LabVIEW,LabVIEW和三菱PLC 通讯
  2. 昂达平板电脑怎么进bios设置u盘为第一启动盘?
  3. 小红书营销:6000字讲透小红书爆文核心引流推广,锦鱼课堂。
  4. SolidWorks模型导入Matlab接口设置的创建
  5. 小学生日记-excel:考勤表加班统计
  6. 奈飞强制1080P播放配置教程
  7. Porter Algorithm ---------词干提取算法
  8. C/C++实现上、下三角矩阵的压缩存储
  9. 直播短视频源码,身份证图片识别
  10. 少年之死的思考:AI能颠覆互联网招聘平台吗?