金蝶K3 SQL报表系列-库存账龄分析
1、创建存储过程:sql代码如下:
create procedure [dbo].[rk_sp_stock_Age]
@paraYear int,
@parePeriod int
as
declare @year int
declare @period int
declare @Fdate datetime
--declare @paraYear int
--declare @parePeriod int
--set @paraYear=2013
--set @parePeriod=10
if @parePeriod=12
begin
set @year=@paraYear+1
set @period=1
end
else
begin
set @year=@paraYear
set @period=@parePeriod+1
end
set @Fdate=convert(datetime,convert(nvarchar(20),@year)+'-'+convert(nvarchar(20),@period)+'-01')-1
select
b.FNumber 物料代码,
b.FName 物料名称,
b.FModel 规格型号,
a.FBegQty/c.Fcoefficient 期末数量,
c.Fname 单位,
a.FBegBal 期末金额,
a.FQty1/c.Fcoefficient [0-29天+数量] ,
a.FAmount1 [0-29天+金额],
a.FQty2/c.Fcoefficient [30-59天+数量],
a.FAmount2 [30-59天+金额],
a.FQty3/c.Fcoefficient [60-89天+数量],
a.FAmount3 [60-89天+金额],
a.FQty4/c.Fcoefficient [90-179天+数量],
a.FAmount4 [90-179天+金额],
a.FQty5/c.Fcoefficient [180-359天+数量],
a.FAmount5 [180-359天+金额],
a.FQty6/c.Fcoefficient [360-719天+数量],
a.FAmount6 [360-719天+金额],
a.FQty7/c.Fcoefficient [720天以上+数量],
a.FAmount7 as[720天以上+金额]
from
(
select
u1.FItemID,
u1.FBegQty,
u1.FBegBal,
u1.FPrice,
case when isnull (u1.FBegQty,0)>=isnull (t1.FQty1,0) then isnull (t1.FQty1,0) else isnull (u1.FBegQty,0) end as FQty1,
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,
case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0) then isnull (t1.FQty2,0)
else case when isnull (u1.FBegQty,0)>=isnull (t1.FQty1,0) then isnull (u1.FBegQty,0)-isnull (t1.FQty1,0)
else 0 end
end as FQty2,
round(case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0) then isnull (t1.FQty2,0)
else
case when isnull (u1.FBegQty,0)>=isnull (t1.FQty1,0) then isnull (u1.FBegQty,0)-isnull (t1.FQty1,0)
else 0 end
end*u1.FPrice,2) as FAmount2,
case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0) then isnull (t1.FQty3,0)
else
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
end as FQty3,
round(case when isnull (u1.FBegQty,0)>isnull (t1.FQty1,0)+isnull (t1.FQty2,0)+isnull (t1.FQty3,0) then isnull (t1.FQty3,0)
else
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
end*u1.FPrice,2) as FAmount3,
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)
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
end as FQty4,
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)
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
end*u1.FPrice,2) as FAmount4,
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)
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
end as FQty5,
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)
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
end*u1.FPrice,2) as FAmount5,
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)
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)
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
end as FQty6,
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)
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)
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
end)*u1.FPrice,2) as FAmount6,
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)
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))
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)
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)
else 0 end
end as FQty7,
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)
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))
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)
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)
else 0 end
end*u1.FPrice,2) as FAmount7
from (
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
) u1
left join
(
select t1.Fitemid,
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,
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,
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,
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,
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,
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,
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
From t_ICItem t1
Join ICStockBill t5 On (t5.FStatus > 0 Or (t5.FUpStockWhenSave > 0 And t5.FCancellation <1 ))
Join ICStockBillEntry t6 On t5.FInterID=t6.FInterID
Where t1.FItemID = t6.FItemID
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))
AND (NOT (t5.FTrantype In (1) AND t5.FPOMode = 36681 ))
and t5.Fdate<=@Fdate and t5.FCancellation=0
group by t1.FItemID
) t1 on u1.FItemID=t1.FItemID
) a
inner join t_ICItem b on a.FItemID=b.FItemID
inner join t_Measureunit c on c.Fitemid=b.FStoreunitid
order by b.Fnumber
2、K3查询分析工具,新增sql关键字:
@Period@ 数字型 手工录入 无
3、K3查询分析工具调用存储过程:
exec rk_sp_stock_Age @Year@,@Period@
金蝶K3 SQL报表系列-库存账龄分析相关推荐
- 金蝶K3 SQL报表系列-委外核销检查表
1.创建存储过程:sp_ICStockBill_Check create procedure [dbo].[sp_ICStockBill_Check] as set nocount on declar ...
- 金蝶K3 SQL报表系列-供应商应付/预付账款明细表
1.创建供应商应付预付账款明细总表存储过程:sp_getAccount_detail,代码如下: create procedure [dbo].[sp_getAccount_detail]@Start ...
- 金蝶K3 SQL报表系列-BOM成本汇总表
1.创建供应商维护价格视图z_view_SupplyRatePrice,代码如下: create view [dbo].[z_view_SupplyRatePrice] as select u1.*, ...
- 金蝶K3 SQL报表系列-客户科目余额表(可用于生成客户保证金查询报表等)
select k3.FNumber 客户代码, k3.FName 客户名称, k2.FNumber 科目代码, k2.FFullName 科目名称, k.FEndBalance 余额from (sel ...
- 金蝶K3 SQL报表系列-供应商科目余额表
创建存储过程:exec sp_get_supply_balance 代码如下: create procedure [dbo].[sp_get_supply_balance] as set nocoun ...
- 金蝶K3 SQL报表系列-委外未勾稽明细表金蝶K3 SQL报表系列-委外未勾稽明细表
select u1.FBillNo 单据编号, u1.FDate 日期, t3.FNumber as 供应商代码, t3.FName as 供应商, t4.FNumber 物料代码, t4.FName ...
- 金蝶K3 SQL报表系列-委外未勾稽明细表
select u1.FBillNo 单据编号, u1.FDate 日期, t3.FNumber as 供应商代码, t3.FName as 供应商, t4.FNumber 物料代码, t4.FName ...
- 金蝶K3直接SQL报表实现动态行转列报表
我们知道,在BOS开发中,想实现动态行转列报表,可以使用交叉分析表来实现,但交叉分析表不太灵活,比如当动态列中有需要复杂的逻辑运算来实现时就无能为力了,下面介绍使用直接SQL报表来实现,也许能给你一点 ...
- Excel+MSSQL开发金蝶K3欠料报表
将K3所有订单需求.MRP运算.库存及在途数据等数据整体展示,适合计划部门根据报表数据统筹考量物料供给情况,特制作此报表及Excel集成工具,以减少手工汇总统计的工作量. 本代码适用于金蝶K3 WIS ...
最新文章
- A - 小C语言--词法分析程序
- WindowsServer2012 R2 64位中文标准版(IIS8.5)下手动搭建PHP环境详细图文教程(二)安装IIS8.5...
- scala中:: , +:, :+, :::, +++的区别
- 我是一个*** (十三)
- socket.io 消息发送
- Eclipse SVN插件Subclipse和Subversive简介
- Windows中的用户和组以及用户密码破解
- Codevs_P1907HDU_P1565 方格取数3(最大流)
- df满足条件的值修改_python – 如何根据其他列中的条件将pandas df列中的多个值更改为np.nan?...
- 全新的服务器debian/ubuntu---校准时间、更新apt,设置ssh远程访问
- 怎么恢复计算机文件查看方式,win7电脑打开方式怎么还原?win7电脑还原打开方式的方法...
- layui时间日期控件laydate设置默认值,并且结束时间大于开始时间
- The nested type test2 cannot hide an enclosing type
- 开源办公OA开发平台使用说明:用车管理应用
- 【NetWorkX实例(4)】Football数据集
- JAVA高考加油,2017年高考加油祝福语
- 红外热成像传感器介绍
- MATLB|基于燃料电池混合动力汽车双层凸优化
- Android Studio 播放bibi声音
- fzyzojP3618 -- [校内训练-互测20180412]士兵的游戏
热门文章
- Labview通讯三菱Q PLC,Labvew TCP通讯三菱PLC ,MCTCP,三菱PLC连接LabVIEW,LabVIEW和三菱PLC 通讯
- 昂达平板电脑怎么进bios设置u盘为第一启动盘?
- 小红书营销:6000字讲透小红书爆文核心引流推广,锦鱼课堂。
- SolidWorks模型导入Matlab接口设置的创建
- 小学生日记-excel:考勤表加班统计
- 奈飞强制1080P播放配置教程
- Porter Algorithm ---------词干提取算法
- C/C++实现上、下三角矩阵的压缩存储
- 直播短视频源码,身份证图片识别
- 少年之死的思考:AI能颠覆互联网招聘平台吗?