|
发表于 2014-10-9 18:13:06
|
显示全部楼层
本帖最后由 APOLLOOOOO 于 2014-10-9 18:20 编辑
用友UFO的报表运行速度慢,公式编辑界面差,我们老早就不用UFO了,都是用Excel+SQL做报表,如现金流量表查询脚本代码:
- /***现金流量表凭证查询***/
- --USE UFDATA_201_2014 --连接指定数据库
- DECLARE @_YEAR smallint = 2014 --确定查询年度
- DECLARE @CodeLin varchar(20) =(SELECT CODINGRULE
- FROM GradeDef_Base
- WHERE KEYWORD = 'code' AND iyear = @_YEAR)
- DECLARE @CodeLin1 int = LEFT (@CodeLin , 1)
- DECLARE @CodeLin2 int = SUBSTRING (@CodeLin , 2 ,1) + @CodeLin1
- DECLARE @CodeLin3 int = SUBSTRING (@CodeLin , 3 ,1) + @CodeLin2
- DECLARE @CodeLin4 int = SUBSTRING (@CodeLin , 4 ,1) + @CodeLin3
- WITH code_CTE AS (SELECT ccode, ccode_name, igrade, bcash | bbank AS 现金
- FROM code
- WHERE iyear = @_YEAR) --科目公用表表达式 (CTE)
- ,GL_accvouch2 AS (SELECT GL_accvouch.iyear AS 年
- ,GL_accvouch.iperiod AS 月
- ,DAY (GL_accvouch.dbill_date) AS 日
- ,GL_accvouch.csign AS 凭证类别
- ,GL_accvouch.i_id
- ,GL_accvouch.ino_id AS 凭证编号
- ,现金科目 = CAST((SELECT code_CTE.现金
- FROM code_CTE
- WHERE GL_accvouch.ccode = code_CTE.ccode)
- AS int)
- FROM GL_accvouch
- WHERE GL_accvouch.iperiod BETWEEN 1 AND 12
- AND GL_accvouch.iflag IS NULL
- AND GL_accvouch.iyear = @_YEAR
- ) --判断现金分录
- SELECT 凭证.iyear AS 年
- ,凭证.iperiod AS 月
- ,DAY (凭证.dbill_date) AS 日
- ,记帐标志 = CASE WHEN 凭证.ibook = 1 THEN '√' ELSE NULL END
- ,凭证.csign AS 凭证类别
- ,凭证.ino_id AS 凭证编号
- ,凭证.cdigest AS 摘要
- ,凭证.ccode AS 科目编码
- ,code.ccode_name AS 科目名称
- ,LEFT (凭证.ccode , @CodeLin1) AS 一级编码
- ,一级科目 = (SELECT code_CTE.ccode_name
- FROM code_CTE
- WHERE LEFT (凭证.ccode , @CodeLin1) = code_CTE.ccode)
- ,二级编码 = CASE WHEN code.igrade > 1 THEN LEFT (凭证.ccode,@CodeLin2) ELSE NULL END
- ,二级科目 = CASE WHEN code.igrade > 1
- THEN (SELECT code_CTE.ccode_name
- FROM code_CTE
- WHERE LEFT (凭证.ccode , @CodeLin2) = code_CTE.ccode)
- ELSE NULL END
- ,现金科目 = CASE WHEN (SELECT code_CTE.现金
- FROM code_CTE
- WHERE 凭证.ccode = code_CTE.ccode) = 1 THEN '√'
- ELSE NULL END
- ,SIGN((SELECT SUM(现金科目)
- FROM GL_accvouch2
- WHERE GL_accvouch2.年 = @_YEAR
- AND GL_accvouch2.月 = 凭证.iperiod
- AND GL_accvouch2.凭证类别 = 凭证.csign
- AND GL_accvouch2.凭证编号 = 凭证.ino_id)) AS 流量标志
- ,主表项目 = CASE WHEN ((SELECT SUM(现金科目)
- FROM GL_accvouch2
- WHERE GL_accvouch2.年 = @_YEAR
- AND GL_accvouch2.月 = 凭证.iperiod
- AND GL_accvouch2.凭证类别 = 凭证.csign
- AND GL_accvouch2.凭证编号 = 凭证.ino_id)) = 0
- THEN NULL --非流量凭证无主表项目
- WHEN (SELECT code_CTE.现金
- FROM code_CTE
- WHERE 凭证.ccode = code_CTE.ccode) = 1
- THEN '现金'
- WHEN LEFT (凭证.ccode , @CodeLin3) IN (66018001,66018002)
- THEN '支付给职工以及为职工支付的现金' --自营工资福利
- WHEN LEFT (凭证.ccode , @CodeLin3) = 660303
- THEN '汇率变动对现金的影响额' --汇兑损益
- WHEN LEFT (凭证.ccode , @CodeLin3) BETWEEN 12210009 AND 12210011
- THEN '购买商品、接受劳务支付的现金' --自营备用金与押金
- WHEN LEFT (凭证.ccode , @CodeLin2) = 122100
- THEN '销售商品、提供劳务收到的现金' --其他自营流水
- WHEN LEFT (凭证.ccode , @CodeLin2) IN (660101,660102)
- THEN '支付给职工以及为职工支付的现金' --工资福利
- WHEN LEFT (凭证.ccode , @CodeLin2) IN (660302,660303)
- THEN '收到的其他与经营活动有关的现金' --财务费用之利息收入、汇兑损益
- WHEN LEFT (凭证.ccode , @CodeLin1) IN (1121,1122,6001,6041,6051)
- THEN '销售商品、提供劳务收到的现金'
- --应收票据、应收账款、主营收入、租赁收入、其他收入
- WHEN LEFT (凭证.ccode , @CodeLin1) IN (1221,6301,6711)
- THEN '收到的其他与经营活动有关的现金' --其他应收、营业外收支
- WHEN LEFT (凭证.ccode , @CodeLin1) IN (1405,1801,2202,6401,6402,6601,6603)
- THEN '购买商品、接受劳务支付的现金'
- --库存商品、长期待摊、应付账款、主营与其他业务成本、销售与财务费用
- WHEN LEFT (凭证.ccode , @CodeLin1) IN (2221,6403,6801)
- THEN '支付的各项税费' --税费
- WHEN LEFT (凭证.ccode , @CodeLin1) = 6111
- THEN '取得投资收益所收到的现金'
- WHEN LEFT (凭证.ccode , @CodeLin1) IN (1601,1604,1701)
- THEN '购建固定资产、无形资产和其他长期资产所支付的现金'
- WHEN LEFT (凭证.ccode , @CodeLin1) IN (4001,4002)
- THEN '吸收投资所收到的现金'
- WHEN LEFT (凭证.ccode , @CodeLin1) = 4104
- THEN '分配股利利润或偿付利息所支付的现金'
- ELSE NULL
- END
- ,附表项目 = CASE
- WHEN LEFT (凭证.ccode , @CodeLin1) = 4103 THEN '净利润'
- WHEN LEFT (凭证.ccode , @CodeLin1) = 1602 THEN '固定资产折旧'
- WHEN LEFT (凭证.ccode , @CodeLin1) = 1801 THEN '待摊费用减少(减:增加)'
- WHEN LEFT (凭证.ccode , @CodeLin1) = 6603 THEN '财务费用'
- WHEN LEFT (凭证.ccode , @CodeLin1) = 6111 THEN '投资损失(减:收益)'
- WHEN LEFT (凭证.ccode , @CodeLin1) = 1405 THEN '存货的减少(减:增加)'
- WHEN LEFT (凭证.ccode , @CodeLin1) IN (1122,1221)
- THEN '经营性应收项目的减少(减:增加)'
- WHEN LEFT (凭证.ccode , @CodeLin1) IN (2202,2221)
- THEN '经营性应付项目的增加(减:减少)'
- ELSE NULL
- END
- ,凭证.md AS 借方金额
- ,凭证.mc AS 贷方金额
- FROM GL_accvouch AS 凭证
- LEFT OUTER JOIN code ON 凭证.ccode = code.ccode
- WHERE 凭证.iperiod BETWEEN 1 AND 12
- AND 凭证.iflag IS NULL
- AND 凭证.iyear = @_YEAR
- --过虑非法月分(期初数据可能会显示0月等)与作废凭证、筛选年度
- AND (((SELECT SUM(现金科目)
- FROM GL_accvouch2
- WHERE GL_accvouch2.年 = @_YEAR
- AND GL_accvouch2.月 = 凭证.iperiod
- AND GL_accvouch2.凭证类别 = 凭证.csign
- AND GL_accvouch2.凭证编号 = 凭证.ino_id)) > 0
- OR LEFT (凭证.ccode , @CodeLin1)
- IN (1122,1221,1405,1602,1801,2202,2221,4103,6111,6603))
- ORDER BY 1,2,5,6
复制代码
|
|