打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
金蝶K3核算项目余额表存储过程

增强的总帐的核算项目余额表,上面增加了客户和业务员的信息,可以统计出应收应付业务员的具体情况

CREATE proc stkd_核算项目余额表     --stkd_核算项目余额表 6,2006,'1131.01'

@period int,
@year int,
@account varchar(10)
as
set nocount on

create table #aa(
faccountid 
int,
faccountnumber 
varchar(50),
faccountname 
varchar(80),
fcurrency 
varchar(10),
fnumber 
varchar(80),
fname 
varchar(80),
femp 
varchar(20),
fdept 
varchar(30),
fbeginc 
decimal(18,2default(0),
fbegind 
decimal(18,2default(0),
finc 
decimal(18,2default(0),
find 
decimal(18,2default(0),
fendc 
decimal(18,2default(0),
fendd 
decimal(18,2default(0)
)

insert into #aa
select tb.faccountid,ta.fnumber,ta.fname,tc.fname,
case when ti.f1=-1 then too.fnumber when ti.f8=-1 then ts.fnumber else '' end,
case when ti.f1=-1 then too.fshortname when ti.f8=-1 then ts.fname else '' end,
case when tid.fitemclassid=1 then te.fname when tid.fitemclassid=8 then tee.fname else '' end,
case when tid.fitemclassid=1 then td.fname when tid.fitemclassid=8 then tdd.fname else '' end,
case when tb.fbeginbalancefor>0 then tb.fbeginbalancefor else 0 end,
case when tb.fbeginbalancefor<0 then -tb.fbeginbalancefor else 0 end,
tb.fdebitfor,tb.fcreditfor,
case when tb.fendbalancefor>0 then tb.fendbalancefor else 0 end,
case when tb.fendbalancefor<0 then -tb.fendbalancefor else 0 end 
from t_balance tb,
t_account ta 
left join t_itemdetail ti on ta.fdetailid=ti.fdetailid,t_itemdetailv tid 
left join t_organization too on tid.fitemid=too.fitemid and tid.fitemclassid=1 
left join t_emp te on too.femployee=te.fitemid left join t_department td on te.fdepartmentid=td.fitemid
left join t_supplier ts on tid.fitemid=ts.fitemid and tid.fitemclassid=8
left join t_emp tee on ts.femployee=tee.fitemid left join t_department tdd on tee.fdepartmentid=tdd.fitemid,
t_currency tc
where tb.faccountid=ta.faccountid and tb.fdetailid=tid.fdetailid 
and tb.fcurrencyid=tc.fcurrencyid and tb.fperiod=@period and tb.fyear=@year and ta.fnumber=@account

delete from #aa where fbeginc=0 and fbegind=0 and finc=0 and find=0

update t1 set t1.fbeginc=t2.fbeginc,t1.fbegind=t2.fbegind,t1.fendc=t2.fendc,t1.fendd=t2.fendd
from #aa t1,(select fcurrency,sum(fbeginc) as fbeginc,sum(fbegind) as fbegind,
sum(fendc) as fendc,sum(fendd) as fendd
from #aa where fnumber is not null group by fcurrency) t2
where t1.fcurrency=t2.fcurrency and t1.fnumber is null
delete from #aa where fcurrency='*'

select faccountnumber as 科目代码,faccountname as 科目名称,fcurrency as 币别,fdept as 部门,femp as 专营业务员,fnumber as 项目代码,
fname 
as 项目名称,fbeginc as 期初借方,fbegind as 期初贷方,finc as 本期借方,FINd as 本期贷方,
fendc 
as 期末借方,fendd as 期末贷方 from #aa order by fdept,femp,fcurrency

drop table #aa


GO

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
更改BOM倒冲属性
金蝶K3系统如何更改已使用物料的计量单位信息
Count(*)和Count(FNumber)区别
SQL Server怎么样自连接查询啊?
Oracle字符串连接的方法
金蝶K3-V10.7财务软件数据库数据导入AO方法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服