--Run this against the company first to create the table
/****** Object: Table [dbo].[IV00102_snapshots] Script Date: 07/04/2013 09:28:43 ******/
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = Object_id(N'[dbo].[IV00102_snapshots]')
AND type IN ( N'U' ))
DROP TABLE [dbo].[iv00102_snapshots]
go
/****** Object: Table [dbo].[IV00102_snapshots] Script Date: 07/04/2013 09:28:43 ******/
SET ansi_nulls ON
go
SET quoted_identifier ON
go
SET ansi_padding OFF
go
CREATE TABLE [dbo].[iv00102_snapshots]
(
[itemnmbr] [CHAR](31) NOT NULL,
[locncode] [CHAR](11) NOT NULL,
[binnmbr] [CHAR](21) NOT NULL,
[rcrdtype] [SMALLINT] NOT NULL,
[primvndr] [CHAR](15) NOT NULL,
[lsordqty] [NUMERIC](19, 5) NOT NULL,
[lrcptqty] [NUMERIC](19, 5) NOT NULL,
[lstorddt] [DATETIME] NOT NULL,
[lsordvnd] [CHAR](15) NOT NULL,
[lsrcptdt] [DATETIME] NOT NULL,
[qtyrqstn] [NUMERIC](19, 5) NOT NULL,
[qtyonord] [NUMERIC](19, 5) NOT NULL,
[qtybkord] [NUMERIC](19, 5) NOT NULL,
[qty_drop_shipped] [NUMERIC](19, 5) NOT NULL,
[qtyinuse] [NUMERIC](19, 5) NOT NULL,
[qtyinsvc] [NUMERIC](19, 5) NOT NULL,
[qtyrtrnd] [NUMERIC](19, 5) NOT NULL,
[qtydmged] [NUMERIC](19, 5) NOT NULL,
[qtyonhnd] [NUMERIC](19, 5) NOT NULL,
[atyalloc] [NUMERIC](19, 5) NOT NULL,
[inactive] [TINYINT] NOT NULL,
[snapdate] [DATETIME] NOT NULL
)
ON [PRIMARY]
go
SET ansi_padding OFF
go
--Setup a daily job to run this script
INSERT INTO iv00102_snapshots
SELECT [itemnmbr],
[locncode],
[binnmbr],
[rcrdtype],
[primvndr],
[lsordqty],
[lrcptqty],
[lstorddt],
[lsordvnd],
[lsrcptdt],
[qtyrqstn],
[qtyonord],
[qtybkord],
[qty_drop_shipped],
[qtyinuse],
[qtyinsvc],
[qtyrtrnd],
[qtydmged],
[qtyonhnd],
[atyalloc],
inactive,
Getdate() AS SnapDate
FROM iv00102
-- Change this number to increase the amount of history kept. Default is 3 years.
DELETE FROM iv00102_snapshots
WHERE Getdate() - snapdate > 1095
No comments:
Post a Comment