U872每月都须要做月结,对于制造企业来说,结算成本处理是不可缺少的一个处理环节,每次查询出来待暂估记录也比較多(我接触到的有3万左右),暂估时间一般要2-3小时左右,若调用的大表索引碎片多时,会须要更长的时间,先看一下处理过程调用的主要步骤及脚本有哪些:

第一步:取存货模块的最新会计期间

SELECT MAX(iPeriod) AS CurMonth FROM GL_mEnd WHERE bFlag_IA=1

第二步:取入库单明细账记录

Select top 1 rdrecords.autoid from rdrecords inner join ia_subsidiary 
    on rdrecords.autoid=ia_subsidiary.id Where ia_subsidiary.CvouType = N'01'
    and isnull(rdrecords.iquantity,0)=isnull(rdrecords.isquantity,0) 
    and rdrecords.autoid=5403479 And ia_subsidiary.imonth=6

第三步:取存货总账表记录

Select * from Ia_Summary 
    where   cinvcode= N'021299000098' And IsNull(iDirect, 0) = 0 
        and IsNull(Ia_Summary.iPeriod, 0) <> 0 And Ia_Summary.iMonth = 6 

第四步:取採购结算单主从档记录

select PSVID from pursettlevouch where PSVID=32128
Select * From PurBillVouchs Where ID=1709941

第五步:取存货明细表记录

Select Autoid From ia_subsidiary 
    Where ID=5403457 And iMonth=6 And (cVouType= N'01' Or (cVouType= N'30' and cSrcVouType=N'01')) 
    
Select iMonth,cPZID ,*  from ia_subsidiary 
    where  (cVouType= N'01' or (cVouType= N'33' and cSrcVouType=N'01')) 
        and (bflag=1 or bflag=2) and id=5403457
Select top 1 * from ia_subsidiary 
    where (CVOUTYPE='01' OR ((CVOUTYPE='33' or CVOUTYPE='30') 
        and csrcvoutype='01' )) and id=5403457 And bFlag=1 order by autoid desc
Select * from ia_subsidiary where  CVOUTYPE= N'24' and id=5403457 and imonth=6 and cSRcvoutype='01'
Select Top 1 * From Ia_Subsidiary Where AutoID=1091064

第六步:新增存货明细账记录

insert into IA_Subsidiary (bRdFlag, cBusType, cBusCode, cVouCode, ID, ValueID, JustID, dVouDate,
    dKeepDate, iMonth, iPZID, cInvHead, cDifHead, cVouType, cPTCode, cSTCode,cWhCode, 
    cInvCode,cAccDep, cRdCode, cCusCode,cBillCode, cDLCode, cPSPCode, cProCode, cDepCode,
    cPersonCode,iAInQuantity,iAOutQuantity, iInCost, iOutCost,iAInPrice, iAOutPrice,
    iDebitDifCost, iCreditDifCost,cBatchCode, cMaker,cAccounter, bFlag, bMoneyFlag, 
    bSale, cMemo,cDefine1, cDefine2, cDefine3,cDefine4, cDefine5, cDefine6,cDefine7, 
    cDefine8, cDefine9,cDefine10, cDefine11,cDefine12,cDefine13,cDefine14,cDefine15,
    cDefine16,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,
    cdefine22,cdefine23,cdefine24,cdefine25,cdefine26,cdefine27,cdefine28,cdefine29,
    cdefine30,cdefine31,cdefine32,cdefine33,cdefine34,cdefine35,cdefine36,cdefine37,
    citem_class,citemcode,citemcname,cVenCode,cHandler,cOrderCode,cARVCode,cName,
    cBatchia,dMadeDateia,iMassDateia,cMassUnit,dVDateia,cproordercode,iproorderid,
    iproorderids,cworkprocode,cworkprocodedis,cworkcentercode,cworkcentername,cendcode,
    csaleordercode,isaleorderid,isaleordersid,isaleorderids,centrustordercode,ientrustorderid,
    ientrustordersid,ipurordersid,idlsid,cAssUnit,inum,strContractCode,cpurordercode,exoCode,
    iExRowno,consignMentCode,iconsignmentautoid,imaterialfee,iprocessfee,cSRcVouType,
    cDemandCode,cDemandMemo,cIMOrdercode)
    values (1,N'普通採购',null,N'TL20140519396',5403457,null,null,'2014-05-19','2014-06-25',
        6,1603742,null,null,N'24',N'01',null,N'07',N'021299000098',N'6901',N'101',null,null,null,
        null,null,null,N'07409',-20,null,1.0769,null,-21.54,null,null,null,null,N'lml',N'lh',
        N'1',0,0,null,N'0911',null,null,null,null,null,0,null,null,null,null,N'PO00001903',
        null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,N'4',
        N'CP140404-040',null,0,0,null,null,N'CPWG1404-075',N'PO00001903',null,null,null,null,
        null,null,null,null,null,N'001587',N'yql',N'TLWG-140400006151',N'TL201405160263',
        null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
        null,null,null,1916612,null,null,null,null,N'TLWG-140400006151',null,null,null,null,null,
        null,N'01',null,null,null)

第七步:取存货档案的核算自由项

Select bCheckFree1,bCheckFree2,bCheckFree3,bCheckFree4,bCheckFree5,bCheckFree6,bCheckFree7,
        bCheckFree8,bCheckFree9,bCheckFree10 FROM inventory where cInvcode= N'021299000098'

第八步:写总账

Exec IA_WriSummary 按仓库核算,2,6, N'07', N'021299000098', N'', N'', N'', N'', N'', 
                    N'', N'', N'', N'', N'',-20,-21.54,0,0,0,0

注:数量是负数

第九步:反复运行第六步的脚本

第十步:写总账

<span style="font-size:12px;">Exec IA_WriSummary 按仓库核算,2,6, N'07', N'021299000098', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'',20,21.54,0,0,0,0</span>

注:数量为正数

结算成本处理涉及到的大表有 出入库明细表rdrecords。总账明细表ia_subsidiary,採购结算单明细表PurBillVouchs

若要保证暂估的速度,须要对优化处理:

第一步:临时禁用SQL代理中的一些计划任务。如备份、同步等

第二步:点【暂估】button前。一定要对rdrecords,Ia_Summary ,ia_subsidiary,PurBillVouchs,Inventory,Ia_Summary 重建或整理索引,索引碎片能够用dbo.fn_ShowIndexSP函数,重建索引能够用Dyl_ReindexNew过程

第三步:检查这些表的索引的碎片是否已所有在10下面。若是表示所有整理成功!

能够做结算成本处理的暂估操作了。

/*
功能:显示指定表的索引碎片
创建人:baronyang
创建时间:2014-07-02
select * from dbo.fn_ShowIndexSP('')
*/
Alter function dbo.fn_ShowIndexSP
(
@tablename varchar(255)
)
returns @table table (tablename varchar(255),indexname varchar(255),spbl int)
as
BEGIN
DECLARE @dbid int,@objid int
select @dbid=DB_ID(),@objid=OBJECT_ID(@tablename)
insert into @table (tablename,indexname,spbl)
SELECT c.name,b.name,avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats(@dbid,@objid,NULL,NULL,NULL) as a
inner JOIN sys.indexes b on a.object_id=b.object_id and a.index_id=b.index_id
inner JOIN sys.objects c on a.object_id=c.object_id
where b.index_id>0 and avg_fragmentation_in_percent>=1
return
end
/*
功能:重建整理
创建人:baronyang
创建时间:2014-07-02
exec Dyl_ReindexNew 'KQ_OtherData'
select * from dbo.fn_showindexsp('KQ_OtherData')
*/
Alter procedure dbo.Dyl_ReindexNew
@TableName varchar(255),
@indexname varchar(255)=''
as
set nocount on declare @dbid int,@objid int,@sql varchar(1000)
select @dbid=DB_ID(),@objid=isnull(OBJECT_ID(@TableName),0)
if @objid=0
BEGIN
print @TableName+'表不存在'
return
End
IF Exists(SELECT * FROM sys.dm_db_index_physical_stats(@dbid,@objid,NULL,NULL,NULL)
where avg_fragmentation_in_percent>30 and index_id>0
) and @objid>0
BEGIN
set @sql='alter index '+case when isnull(@indexname,'')<>'' THEN @indexname else 'all' END
+' on '+@TableName+' rebuild WITH(online=on,STATISTICS_NORECOMPUTE=ON)'
exec (@SQL)
End IF Exists(SELECT * FROM sys.dm_db_index_physical_stats(@dbid,@objid,NULL,NULL,NULL)
where avg_fragmentation_in_percent>30 and index_id>0 and @objid>0
)
print @TableName+'表索引碎片还是超过30。请手动重建索引'

U872-结算成本处理步骤及索引处理的更多相关文章

  1. 使用SQL Server 2000索引视图提高性能

    什么是索引视图? 许多年来,Microsoft? SQL Server? 一直都提供创建虚拟表(称为视图)的功能.在过去,这些视图主要有两种用途: 提供安全机制,将用户限制在一个或多个基表中的数据的某 ...

  2. Mysql 索引原理及优化

    本文内容主要来源于互联网上主流文章,只是按照个人理解稍作整合,后面附有参考链接. 一.摘要 本文以MySQL数据库为研究对象,讨论与数据库索引相关的一些话题.特别需要说明的是,MySQL支持诸多存储引 ...

  3. SD从零开始47-50, 装运成本基础、控制、结算, 信用/风险管理概述

    [原创] SD从零开始47 装运成本基础 详细的装运成本处理Shipment Cost Processing in Detail 装运成本计算和装运成本结算可用于内向和外向交货: 装运成本记录在一张新 ...

  4. (转)Mysql 索引原理及优化

    本文内容主要来源于互联网上主流文章,只是按照个人理解稍作整合,后面附有参考链接. 一.摘要 本文以MySQL数据库为研究对象,讨论与数据库索引相关的一些话题.特别需要说明的是,MySQL支持诸多存储引 ...

  5. SQL Server 索引知识-应用,维护

    创建聚集索引 a索引键最好唯一(如果不唯一会隐形建立uniquier列(4字节)确保唯一,也就是这列都会复制到所有非聚集索引中) b聚集索引列所占空间应尽量小(否则也会使非聚集索引的空间变大) c聚集 ...

  6. SQL Server 查询优化 索引的结构与分类

    一.索引的结构 关系型数据库中以二维表来表达关系模型,表中的数据以页的形式存储在磁盘上,在SQL SERVER中,数据页是磁盘上8k的连续空间,那么,一个表的所有数据页在磁盘上是如何组织的呢?分两种情 ...

  7. sql server 索引总结三

    一.非聚集索引维护 非聚集索引的行定位器值保持相同的聚集索引值,即使该聚集索引列物理上重新定位后,也是如此. 为了优化这个维护开销,SQL Server添加一个指向旧数据页的指针,以在页面分割之后指向 ...

  8. SQLServer存储引擎——06.索引的遍历与维护

    一.遍历 索引树的每个节点都是一个页面. 索引树有三种类型的节点:根节点.中间节点.叶子节点. (1) 根节点与中间节点一样,只包含下一层节点的入口值与入口指针,它们称为索引节点: (2) 叶子节点包 ...

  9. 为何在查询中索引未被使用 (Doc ID 1549181.1)

        To Bottom * 为何在查询中索引未被使用 (Doc ID 1549181.1) To Bottom 文档内容 用途   排错步骤   高速检查   表上是否存在索引?   索引是否应该 ...

随机推荐

  1. Python学习笔记(七)—字典的学习

    总结内容: 1.字典的定义 2.字典的好处 3.字典的增删改查 4.字典常用方法及内置函数 5.字典的多层嵌套 6.字典的循环 7.字典小练习 1.字典的定义 字典是另一种可变容器模型,且可存储任意类 ...

  2. mysql慢查询配置

    1.慢查询有什么用? 能记录下所有执行超过long_query_time时间的SQL语句, 帮你找到执行慢的SQL, 方便我们对这些SQL进行优化. 2. 如何开启慢查询? 首先我们先查看MYSQL服 ...

  3. MySQL内核整理(一)

    一.在共享表空间(系统表空间)中,innodb会维护一些系统信息:1.Internal data dictionary2.Rollback segments3.undo space4.insert b ...

  4. cat ,more ,less 命令的使用和差别

    cat命令功能用于显示整个文件的内容单独使用没有翻页功能因此常常和more命令搭配使用,cat命令还有就是将数个文件合并成一个文件的功能. more命令功能:让画面在显示满一页时暂停,此时可按空格健继 ...

  5. 关于Google Android平台的ClockworkMod Recovery恢复模式

    lockworkMod Recovery,它也被称为Clockwork与CWM,它是装载Google Android操作系统设备的一个自定义的Recovery恢复模式,它可以使得相关Android设备 ...

  6. Make a DAC with a microcontroller's PWM timer

    http://www.edn.com/design/analog/4337128/Make-a-DAC-with-a-microcontroller-s-PWM-timer Many embedded ...

  7. Linux下的两个经典宏定义 转

    http://www.linuxidc.com/Linux/2016-08/134481.htm http://www.linuxidc.com/Linux/2013-01/78003.htm htt ...

  8. 解决win8内置管理员无法激活此应用

    解决win8内置管理员无法激活此应用 方法/步骤   在运行中输入:“gpedit.msc”,就会启动组策略编辑器.   依次展开“计算机配置”里面的 “Windows设置” “安全设置” “本地策略 ...

  9. 【Nginx】ngx_event_core_module模块

    ngx_event_core_module模块属于事件模块,它是其他事件类模块的基础.它主要完毕下面任务: 创建连接池 决定使用哪些事件驱动机制 初始化将要使用的事件模块 以下分析该模块的代码. ng ...

  10. Weblogic下启用Gzip压缩

    一.首先,去http://sourceforge.net/projects/filterlib网站下载tk-filters-1.0.1.zip. 二.解压这个tk-filters-1.0.1.zip压 ...