当前位置:文档之家› excel表格查询数据库

excel表格查询数据库

竭诚为您提供优质文档/双击可除excel表格查询数据库
篇一:excel+sql查询表
/***现金流量表凭证查询***/
-
-useuFdata_201_20xx--连接指定数据库
declaRe@_yeaRsmallint=20xx--确定查询年度
declaRe@codelinvarchar(20)=(selectcodingRule
FRom
gradedef_base
wheRekeywoRd
=codeandiyear=@_yeaR)
declaRe@codelin1int=leFt(@codelin,1)
declaRe@codelin2int=substRing(@codelin,2,1)+@codeli n1
declaRe@codelin3int=substRing(@codelin,3,1)+@codeli n2
declaRe@codelin4int=substRing(@codelin,4,1)+@codeli n3
withcode_cteas(selectccode,ccode_name,igrade,bcash| bbankas现金
FRomcode
wheReiyear=@_yeaR)--科目公用表表达式
(cte)
,gl_accvouch2as(selectgl_accvouch.iyearas年
,gl_accvouch.iperiodas月
,day
(gl_accvouch.dbill_date)as日
,gl_accvouch.csignas凭
证类别
,gl_accvouch.i_id
,gl_accvouch.ino_idas凭
证编号
,现金科目=cast((select
code_cte.现金
FRomcode_cte
wheRegl_ode=code_ode)
asint)
FRomgl_accvouch
wheRegl_accvouch.iperiodbetween1and12
and
gl_accvouch.iflagisnull
and
gl_accvouch.iyear=@_yeaR
)--判断现金分录
select凭证.iyearas年
,凭证.iperiodas月
,day(凭证.dbill_date)as日
,记帐标志=casewhen凭证.ibook=1then√elsenullend ,凭证.csignas凭证类别
,凭证.ino_idas凭证编号
,凭证.cdigestas摘要
,凭证.ccodeas科目编码
,ode_nameas科目名称
,leFt(凭证.ccode,@codelin1)as一级编码
,一级科目=(selectcode_ode_name
FRomcode_cte
wheReleFt(凭证.ccode,@codelin1)=code_ode) ,二级编码=casewhencode.igrade>1thenleFt(凭
证.ccode,@codelin2)elsenullend
,二级科目=casewhencode.igrade>1
then(selectcode_ode_name
FRomcode_ctewheReleFt(凭
证.ccode,@codelin2)=code_ode)
elsenullend
,现金科目=casewhen(selectcode_cte.现金
FRomcode_ctewheRe
证.ccode=code_ode)=1then√
elsenullend
,sign((selectsum(现金科目)
FRomgl_accvouch2凭
wheRegl_accvouch2.年=@_yeaR
andgl_accvouch2.月=凭证.iperiod
andgl_accvouch2.凭证类别=凭证.csign
andgl_accvouch2.凭证编号=凭证.ino_id))as流量标志
,主表项目=casewhen((selectsum(现金科目)
FRomgl_accvouch2
wheRegl_accvouch2.年=@_yeaR
andgl_accvouch2.月=凭证.iperiod
andgl_accvouch2.凭证类别=凭证.csign
andgl_accvouch2.凭证编号=凭证.ino_id))=0
thennull--非流量凭证无主表项目
when(selectcode_cte.现金
FRomcode_cte
wheRe凭证.ccode=code_ode)=1
then现金
whenleFt(凭
证.ccode,@codelin3)in(66018001,66018002)
then支付给职工以及为职工支付的现金--自营工资福利whenleFt(凭证.ccode,@codelin3)=660303
then汇率变动对现金的影响额--汇兑损益
whenleFt(凭
证.ccode,@codelin3)between12210009and12210011then购买商品、接受劳务支付的现金--自营备用金与押金whenleFt(凭证.ccode,@codelin2)=122100
then销售商品、提供劳务收到的现金--其他自营流水
whenleFt(凭证.ccode,@codelin2)in(660101,660102) then支付给职工以及为职工支付的现金--工资福利
whenleFt(凭证.ccode,@codelin2)in(660302,660303) then收到的其他与经营活动有关的现金--财务费用之。

相关主题