24周年

财税实务 高薪就业 学历教育
APP下载
APP下载新用户扫码下载
立享专属优惠

安卓版本:8.7.50 苹果版本:8.7.50

开发者:北京正保会计科技有限公司

应用涉及权限:查看权限>

APP隐私政策:查看政策>

HD版本上线:点击下载>

利用SQL游标核对银行对账单与银行日记账

来源: 张金芳 编辑: 2010/01/25 13:19:04  字体:

  核对银行对账单与单位银行日记账(以下简称单位日记账)是对银行存款审计中一项重要的步骤。通过核对银行对账单与单位日记账,可以查找出未达账项,从而为发现出租、出借帐户、挪用公款,非法出借资金等违纪问题提供线索。以往查找未达账项采用的是手工逐行勾挑的方法。这种方法耗时长,准确性不高。尤其是对一些存取款业务频繁的单位,手工核对更是显得力不从心。而利用SQL游标则可以快速查找未达账项,从而取得事半功倍的效果。

  一、采集银行对账单和单位日记账数据,并进行必要的整理转换,使其对应字段的长度、数据类型相同。如:通常银行日记账的支票号为银行对账单的凭证号的后四位,因此应对银行对账单的凭证号作截断处理。Update 银行对账单 set 凭证号=right(凭证号,4)

  二、对应整理后的银行对账单和单位日记账创建四个空表用于接收未达账项记录:单位已付银行未付、单位已收银行未收、银行已付单位未付、银行已收单位未收。如:

  create table 单位已付银行未付 (凭证日期 varchar(14),摘要 nvarchar(50),支票号 nvarchar(10),借方金额 money,贷方金额 money)

  create table 单位已收银行未收 (凭证日期 varchar(14),摘要 nvarchar(50),支票号 nvarchar(10),借方金额 money,贷方金额 money)

  create table 银行已付单位未付 (凭证日期 varchar(14),摘要 nvarchar(50),凭证号 nvarchar(10),借方金额 money,贷方金额 money)

  create table 银行已收单位未收 (凭证日期 varchar(14),摘要 nvarchar(50),凭证号 nvarchar(10),借方金额 money,贷方金额 money)

  三、创建游标,将所有金额以是否有重复金额为条件分为相同金额和不同金额记录,再做对应比较,分步筛选未达账项:

  1、筛选单位日记账不同金额借方有银行对账单贷方无的记录

  declare cur1 cursor for select 借方金额 from 单位日记账 where 借方金额 in (select 借方金额 from 单位日记账 group by 借方金额 having count(借方金额)=1)

  open cur1

  declare @借方金额 money

  fetch next from cur1 into @借方金额

  while @@fetch_status=0

  begin

  if @借方金额 in (select 贷方金额 from 银行对账单 group by 贷方金额 having count(贷方金额)=1)

  fetch next from cur1 into @借方金额

  else

  begin

  insert into 单位已收银行未收 select * from 单位日记账 where 借方金额=@借方金额

  fetch next from cur1 into @借方金额

  end

  end

  close cur1

  deallocate cur1

  2、筛选单位日记账不同金额贷方有银行对账单借方无的记录

  declare cur1 cursor for select 贷方金额 from 单位日记账 group by 贷方金额 having count(贷方金额)=1

  open cur1

  declare @贷方金额 money

  fetch next from cur1 into @贷方金额

  while @@fetch_status=0

  begin

  if @贷方金额 in (select 借方金额 from 银行对账单

  group by 借方金额 having count(借方金额)=1)

  fetch next from cur1 into @贷方金额

  else

  begin

  insert into 单位已付银行未付 select * from 单位日记账 where 贷方金额=@贷方金额

  fetch next from cur1 into @贷方金额

  end

  end

  close cur1

  deallocate cur1

  3、筛选单位日记账相同金额借方有银行对账单贷方无的记录

  declare cur1 cursor for select 借方金额,count(*) 个数 from 单位日记账 where 借方金额0 group by 借方金额 having count(借方金额)>1

  open cur1

  declare @借方金额 money,@个数 int

  fetch next from cur1 into @借方金额,@个数

  while @@fetch_status=0

  begin

  if @个数 =(select count(*) from 银行对账单 where 贷方金额=@借方金额)

  fetch next from cur1 into @借方金额,@个数

  else

  begin

  insert into 单位已收银行未收 select * from 单位日记账 where 借方金额=@借方金额

  fetch next from cur1 into @借方金额,@个数

  end

  end

  close cur1

  deallocate cur1

  4、筛选单位日记账相同金额贷方有银行对账单借方无的记录

  declare cur1 cursor for select 贷方金额,count(*) 个数 from 单位日记账 where 贷方金额0 group by 贷方金额 having count(借方金额)>1

  open cur1

  declare @贷方金额 money,@个数 int

  fetch next from cur1 into @贷方金额,@个数

  while @@fetch_status=0

  begin

  if @个数 =(select count(*) from 银行对账单 where 借方金额=@贷方金额)

  fetch next from cur1 into @贷方金额,@个数

  else

  begin

  insert into 单位已付银行未付 select * from 单位日记账 where 支票号 is null and 贷方金额=@贷方金额

  declare cur2 cursor for select 支票号 from 单位日记账 where 贷方金额=@贷方金额 and 支票号 is not null

  open cur2

  declare @支票号 varchar(10)

  fetch next from cur2 into @支票号

  while @@fetch_status=0

  begin

  if @支票号 in (select 凭证号 from 银行对账单 where 借方金额=@贷方金额)

  fetch next from cur2 into @支票号

  else

  begin

  insert into 单位已付银行未付 select * from 单位日记账 where 支票号=@支票号

  fetch next from cur2 into @支票号

  end

  end

  close cur2

  deallocate cur2

  fetch next from cur1 into @贷方金额,@个数

  end

  end

  close cur1

  deallocate cur1

  5、筛选银行对账单不同金额借方有单位日记账贷方无的记录

  declare cur1 cursor for select 借方金额 from 银行对账单 group by 借方金额 having count(借方金额)=1

  open cur1

  declare @借方金额 money

  fetch next from cur1 into @借方金额

  while @@fetch_status=0

  begin

  if @借方金额 in (select 贷方金额 from 单位日记账 group by 贷方金额 having count(贷方金额)=1)

  fetch next from cur1 into @借方金额

  else

  begin

  insert into 银行已付单位未付 select * from 银行对账单 where 借方金额=@借方金额

  fetch next from cur1 into @借方金额

  end

  end

  close cur1

  deallocate cur1

  6、筛选银行对账单不同金额贷方有单位日记账借方无的记录

  declare cur1 cursor for select 贷方金额 from 银行对账单 group by 贷方金额 having count(贷方金额)=1

  open cur1

  declare @贷方金额 money

  fetch next from cur1 into @贷方金额

  while @@fetch_status=0

  begin

  if @贷方金额 in (select 借方金额 from 单位日记账

  group by 借方金额 having count(借方金额)=1)

  fetch next from cur1 into @贷方金额

  else

  begin

  insert into 银行已收单位未收 select * from 银行对账单 where 贷方金额=@贷方金额

  fetch next from cur1 into @贷方金额

  end

  end

  close cur1

  deallocate cur1

  7、筛选银行对账单相同金额借方有单位日记账贷方无的记录

  declare cur1 cursor for select 借方金额,count(*) 个数 from 银行对账单 where 借方金额0 group by 借方金额 having count(借方金额)>1

  open cur1

  declare @借方金额 money,@个数 int

  fetch next from cur1 into @借方金额,@个数

  while @@fetch_status=0

  begin

  if @个数 =(select count(*) from 单位日记账 where 贷方金额=@借方金额)

  fetch next from cur1 into @借方金额,@个数

  else

  begin

  insert into 银行已付单位未付 select * from 银行对账单 where 凭证号 is null and 借方金额=@借方金额

  declare cur2 cursor for select 凭证号 from 银行对账单 where 借方金额=@借方金额 and 凭证号 is not null

  open cur2

  declare @凭证号 varchar(10)

  fetch next from cur2 into @凭证号

  while @@fetch_status=0

  begin

  if @凭证号 in (select 支票号 from 单位日记账 where 贷方金额=@借方金额)

  fetch next from cur2 into @凭证号

  else

  begin

  insert into 银行已付单位未付 select * from 银行对账单 where 凭证号=@凭证号

  fetch next from cur2 into @凭证号

  end

  end

  close cur2

  deallocate cur2

  fetch next from cur1 into @借方金额,@个数

  end

  end

  close cur1

  deallocate cur1

  8、筛选银行对账单相同金额贷方有单位日记账借方无的记录

  declare cur1 cursor for select 贷方金额,count(*) 个数 from 银行对账单 where 贷方金额0 group by 贷方金额 having count(借方金额)>1

  open cur1

  declare @贷方金额 money,@个数 int

  fetch next from cur1 into @贷方金额,@个数

  while @@fetch_status=0

  begin

  if @个数 =(select count(*) from 单位日记账 where 借方金额=@贷方金额)

  fetch next from cur1 into @贷方金额,@个数

  else

  begin

  insert into 银行已收单位未收 select * from 银行对账单 where 贷方金额=@贷方金额

  fetch next from cur1 into @贷方金额,@个数

  end

  end

  close cur1

  deallocate cur1

责任编辑:zoe

实务学习指南

回到顶部
折叠
网站地图

Copyright © 2000 - www.chinaacc.com All Rights Reserved. 北京正保会计科技有限公司 版权所有

京B2-20200959 京ICP备20012371号-7 出版物经营许可证 京公网安备 11010802044457号