一个非常有用的Sbo业务查询分析,利用Sbo单据事务日志表OINM,对指定期间的物料的期初、期末、入库、出库以及特殊类型的出库入库--在此我们分析了采购入库和采购退货两种特殊的业务类型--进行了统计分析。
当然可以进行扩展,进而加上一些分析条件,比如对指定的仓库、指定的物料类型、排除指定的物料等条件进行约束。以下语句在某合作单位的生产环境上测试通过,并用于其生产分析。
_declare @dt1 smalldatetime, @dt2 smalldatetime, @ItemCode nvarchar(20)
_select @dt1=t0.docDate FROM OINM t0 WHERE t0.createDate=[%0]
_select @dt2=t1.docDate FROM OINM t1 WHERE t1.createDate=[%1]
_select @ItemCode=t2.ItemCode from OITM t2 where t2.ItemCode = '[%2]'
_select tc.ItmsGrpNam N'物料组名称',tc.ItmsGrpCod N'物料组',ta.itemcode N'物料号',tb.ItemName N'物料名称',sum(ta.begqty) N'期初数量',sum(ta.begtotal) N'期初金额', sum(Buyqty) N'采购入库数量',sum(Buytotal) N'采购入库金额',sum(Retqty) N'采购退货数量',sum(Rettotal) N'采购退货金额',sum(inqty) N'库存收货数量',sum(intotal) N'库存收货金额',sum(outqty) N'库存发货数量',sum(outtotal) N'库存发货金额',sum(endqty) N'期未数量',sum(endtotal) N'期未余额'
from (
 _select ItemCode,sum(begqty) begqty,sum(begtotal) begtotal,sum(inqty)inqty,sum(intotal)intotal,sum(outqty) outqty,sum(outtotal) outtotal,sum(endqty) endqty,sum(endtotal) endtotal, sum(BuyQty) BuyQty, sum(BuyTotal) BuyTotal, sum(RetQty) RetQty, sum(RetTotal) RetTotal
  FROM 
   (
       _select a.ItemCode,sum(IsNull(IsNull(a.InQty,0),0)-IsNull(IsNull(a.OutQty,0),0)) begqty,sum(a.TransValue) begtotal,0 inqty,0 intotal,0 outqty,0 outtotal,0 endqty,0 endtotal, 0 BuyQty, 0 BuyTotal, 0 RetQty, 0 RetTotal
        from oinm a 
    where (a.ItemCode=@ItemCode or IsNull(@ItemCode,'')='') and a.CreateDate < IsNull(@dt1, cast('2001-1-1' as smalldatetime))
       group by a.ItemCode
       union all
       _select a.ItemCode,0,0,sum(IsNull(a.InQty,0)),sum(case when a.TransValue>=0 then a.TransValue else 0 end),sum(IsNull(a.OutQty,0)),sum(case when a.TransValue<0 then a.TransValue else 0 end),0,0,0,0,0,0
        from oinm a 
    where (a.ItemCode=@ItemCode or IsNull(@ItemCode,'')='') and a.CreateDate between IsNull(@dt1, cast('2001-1-1' as smalldatetime)) and IsNull(@dt2,getdate()) And a.TransType not in ('20','21')
        group by a.ItemCode
       union all
       _select a.ItemCode,0,0,0,0,0,0,sum(IsNull(IsNull(a.InQty,0),0)-IsNull(IsNull(a.OutQty,0),0)),sum(a.TransValue),0,0,0,0
        from oinm a 
    where (a.ItemCode=@ItemCode or IsNull(@ItemCode,'')='') and a.CreateDate<=IsNull(@dt2,getdate())
        group by a.ItemCode
       union all
       _select a.ItemCode,0,0,0,0,0,0,0,0,sum(IsNull(IsNull(a.InQty,0),0)-IsNull(IsNull(a.OutQty,0),0)),sum(a.TransValue),0,0
        from oinm a 
    where (a.ItemCode=@ItemCode or IsNull(@ItemCode,'')='') and a.CreateDate between IsNull(@dt1, cast('2001-1-1' as smalldatetime)) and IsNull(@dt2,getdate()) and a.TransType='20'
        group by a.ItemCode
       union all
       _select a.ItemCode,0,0,0,0,0,0,0,0,0,0,sum(IsNull(IsNull(a.InQty,0),0)-IsNull(IsNull(a.OutQty,0),0)),sum(a.TransValue)
        from oinm a 
    where (a.ItemCode=@ItemCode or IsNull(@ItemCode,'')='') and a.CreateDate between IsNull(@dt1, cast('2001-1-1' as smalldatetime)) and IsNull(@dt2,getdate()) and a.TransType='21'
        group by a.ItemCode
   ) tmp 
   group by ItemCode) ta 
  inner join oitm tb on ta.itemcode = tb.ItemCode 
  inner join oitb tc on tb.ItmsGrpCod = tc.ItmsGrpCod 
group by tc.ItmsGrpNam, tc.ItmsGrpCod, ta.itemcode, tb.ItemName
本文转自foresun  51CTO博客,原文链接:http://blog.51cto.com/foresun/104533,如需转载请自行联系原作者

在Sbo中通过单据事务日志进行物料的期初、期末、出入库综合分析相关推荐

  1. fn_dblog_如何使用fn_dblog和fn_dump_dblog直接在SQL Server数据库中连续读取事务日志文件数据

    fn_dblog 大纲 (Outline) In this article, we'll discuss how to read SQL Server transaction logs. This a ...

  2. oracle数据库事务日志已满,SQL Server中已满事务日志原因的检测(上)

    对于SQL Server数据库管理员来讲,已满事务日志是一个琐碎的,但又很常见的问题.它能引发事务的提前终止,甚至通过阻止所有事务的引入,从而引起系统的崩溃.对于数据库管理员来说,关键是理解将要发生的 ...

  3. SQL Server中已满事务日志原因的检测

    对于SQL Server数据库管理员来讲,已满事务日志是一个琐碎的,但又很常见的问题.它能引发事务的提前终止,甚至通过阻止所有事务的引入,从而引起系统的崩溃.对于数据库管理员来说,关键是理解将要发生的 ...

  4. ib_logfile和mysql_bin_mysql的innodb中事务日志ib_logfile

    mysql的innodb中事务日志ib_logfile 事务日志或称redo日志,在mysql中默认以ib_logfile0,ib_logfile1名称存在,可以手工修改参数,调节 开启几组日志来服务 ...

  5. 什么是SQL Server事务日志中的虚拟日志文件?

    什么是SQL Server事务日志文件? (What is a SQL Server transaction log file?) SQL Server事务日志文件是每个SQL Server数据库的组 ...

  6. mysql ib_logfile 数量_Mysql 事务日志(Ib_logfile)

    mysql的innodb中事务日志ib_logfile(0/1) 概念: 事务日志或称redo日志,在mysql中默认以ib_logfile0,ib_logfile1名称存在,可以手工修改参数,调节开 ...

  7. SQL Server移除事务日志后sys.master_files依然存在记录问题

    在SQL Server中移除了事务日志文件后,使用sys.master_files检查时发现,对应的事务日志文件记录信息依然存在sys.master_files里面,只是状态state_desc为OF ...

  8. mysql备份时候事务日志_SQLSERVER备份事务日志的作用

    SQLSERVER备份事务日志的作用 事务日志备份有以下3种类型 (1)纯日志备份:仅包含相隔一段时间的事务日志记录,而不包含任何大容量更改 (2)大容量操作日志备份.包括由大容量操作更改的日志和数据 ...

  9. MySQL日志:binlog、事务日志(redo、undo)

    事务的隔离性是通过锁实现,而事务的原子性.一致性和持久性则是通过日志实现.Mysql的日志可以分为: binlog:server层实现 事务日志:包括redo log.undo log,引擎层(inn ...

  10. 有关SQL Server事务日志的十大文章

    了解SQL Server中的日志记录和恢复 (Understanding Logging and Recovery in SQL Server) "Understanding Logging ...

最新文章

  1. 解决ngnix服务器上的Discuz!x2.5 Upload Error:413错误
  2. Python 中 pass的使用
  3. 泽西岛/贾克斯RS:流式JSON
  4. java lookandfeel nimbus_动态改变LookAndFeel
  5. c++ 确定百分比_【文献笔记】JIMF中国货币政策的不确定性
  6. (python)7-6 sdut-数制转换
  7. 微软源代码遭 SolarWinds 黑客访问
  8. JavaMail 发送邮件的实例
  9. 感谢第一个和第二个付费客户对我的信任
  10. 电商狂欢6月之代码也疯狂
  11. 并行编程--MPI开发入门
  12. 基于TQ2440的SPI驱动学习(OLED)
  13. Robot Framework Selenium UI自动化测试 --- 实战篇
  14. Dede文章标题及文章摘要长度修改_元曦血狼_新浪博客
  15. Python MySQLdb 模块使用方法
  16. 19-图片标签注意点
  17. 怎么把计算机里的文件放到桌面上,ipad怎么把文件放到桌面
  18. 【2022年第一期 CANN训练营学习笔记】进阶班应用开发课 大作业1-开发DVPP应用,输入,输出都是JPEG图片,且分辨率不同
  19. Google的招聘要求
  20. Mathematica和Wolfram语言面向数学的入门指南:三角函数

热门文章

  1. 记录一次解决后端接口设置cookie设置不上去经过,一级域名可以设置上去cookie,二级域名设置不上cookie
  2. 31个惊艳的数据可视化作品,感受“数据之美”!
  3. 如何用PPT做一张高大上的照片
  4. NameNode作用
  5. 单片机基础教程那么多,什么样才是靠谱的学习方式
  6. java mian是什么_java mian方法详解
  7. 小散量化炒股记|Python也能量化财务指标!教你用净资产收益率选股!
  8. Nested transactions are not supported TransactionScope 多线程事务
  9. 《Adobe Photoshop CS6中文版经典教程》目录—导读
  10. 两天两夜,1M图片优化到100kb