库龄查询

ExpandedBlockStart.gif 代码
USE   [ DEV_WXT ]
GO
/* ***** Object:  StoredProcedure [dbo].[usp_GetInventory_Age]    Script Date: 08/19/2010 17:19:13 ***** */
SET  ANSI_NULLS  ON
GO
SET  QUOTED_IDENTIFIER  ON
GO
ALTER   PROCEDURE   [ dbo ] . [ usp_GetInventory_Age ] (
@strCustCode   nvarchar ( 20 ),
@strSiteCode   nvarchar ( 20 )
)


AS

select   10   as  seq, ' STK '   as  SUBINV,
0   as  QTY3, convert ( decimal ( 19 , 2 ), 0 as  AMT3,
0   as  QTY6, convert ( decimal ( 19 , 2 ), 0 as  AMT6,
0   as  QTY12, convert ( decimal ( 19 , 2 ), 0 as  AMT12,
0   as  QTY24, convert ( decimal ( 19 , 2 ), 0 as  AMT24,
0   as  QTYOVER24, convert ( decimal ( 19 , 2 ), 0 as  AMTOVER24  into  # temp

insert   into  # temp
select   30   as  seq, ' DMG '   as  SUBINV,
0   as  QTY3, convert ( decimal ( 19 , 2 ), 0 as  AMT3,
0   as  QTY6, convert ( decimal ( 19 , 2 ), 0 as  AMT6,
0   as  QTY12, convert ( decimal ( 19 , 2 ), 0 as  AMT12,
0   as  QTY24, convert ( decimal ( 19 , 2 ), 0 as  AMT24,
0   as  QTYOVER24, convert ( decimal ( 19 , 2 ), 0 as  AMTOVER24


SELECT  BRAND,ItemNo,SUBINV,COST,QTY, DATEDIFF ( month ,InboundDate, getdate ())  as  month1  into  #temp1
 
FROM  SYS_Inventory  WHERE  ItemNo = @strCustCode   and   SITECODE = @strSiteCode   AND  QTY > 0



UPDATE  #temp1  set  month1 = 3   where  month1 > 0   and  month1 <= 3
UPDATE  #temp1  set  month1 = 6   where  month1 > 3   and  month1 <= 6
UPDATE  #temp1  set  month1 = 12   where  month1 > 6   and  month1 <= 12
UPDATE  #temp1  set  month1 = 24   where  month1 > 12   and  month1 <= 24
UPDATE  #temp1  set  month1 = 999   where  month1 > 24

select  subinv,month1, sum (qty)  as  qty, sum (cost * qty)  as  amt  into  #temp2  from  #temp1  group   by  SUBINV,month1

update  # temp   set  QTY3 = b.qty,AMT3 = b.amt  from  # temp  a,#temp2 b
where  a.subinv = b.subinv  and  month1 = 3

update  # temp   set  QTY6 = b.qty,AMT6 = b.amt  from  # temp  a,#temp2 b
where  a.subinv = b.subinv  and  month1 = 6

update  # temp   set  QTY12 = b.qty,AMT12 = b.amt  from  # temp  a,#temp2 b
where  a.subinv = b.subinv  and  month1 = 12

update  # temp   set  QTY24 = b.qty,AMT24 = b.amt  from  # temp  a,#temp2 b
where  a.subinv = b.subinv  and  month1 = 24

update  # temp   set  QTYOVER24 = b.qty,AMTOVER24 = b.amt  from  # temp  a,#temp2 b
where  a.subinv = b.subinv  and  month1 = 999

insert   into  # temp
select   40 , ' 总计 ' , sum (QTY3), sum (AMT3), sum (QTY6), sum (AMT6),
sum (QTY12), sum (AMT12), sum (QTY24), sum (AMT24), sum (QTYOVER24), sum (AMTOVER24)  from  # temp

select   *   from  # temp   order   by  seq

drop   table  # temp ,#temp1,#temp2

 

转载于:https://www.cnblogs.com/dthom/articles/1803731.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在SQL Server中,库龄表是指用于追踪数据中每个对象的创建时间、修改时间和删除时间的特定表。它记录了数据中各个对象的历史更改信息,可用于监控数据的变化和审核数据中的操作。 库龄表通常包含以下列: 1. 对象名称(Name):记录对象的名称,如表名、视图名、存储过程名等。 2. 对象类型(Type):记录对象的类型,如表、视图、存储过程、触发器等。 3. 创建时间(Create Time):记录对象的创建时间,表示对象被创建的日期和时间。 4. 修改时间(Modify Time):记录对象的最后修改时间,表示对象被修改的日期和时间。 5. 删除时间(Delete Time):记录对象的删除时间,表示对象被删除的日期和时间。如果对象尚未被删除,则该列为空。 通过库龄表,可以追踪数据内每个对象的历史信息,包括创建和修改的时间。这对于数据管理和维护非常有用。例如,当需要了解特定对象的创建和修改历史时,可以查询库龄表来获取相关信息。此外,库龄表还可以用于审计目的,可以查看特定时间段内对象的更改记录,以便跟踪数据的变化。 维护库龄表的方法可以通过触发器或定时任务来实现。当有新对象被创建、修改或者删除时,触发器会在相应的操作发生时自动更新库龄表。另外,也可以使用定时任务定期扫描数据并更新库龄表。 总之,库龄表是一种用于追踪数据对象历史变更信息的特定表,它可以帮助数据管理员跟踪和管理数据的变化,并提供审计功能,以支持数据的维护和监控。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值