drop create data ... along with SQL
use tempdb
go
DROP TABLE ITEM_VOL
CREATE TABLE [dbo].[ITEM_VOL](
[EVENT_GROUP_ID] [char](32) NULL,
[ITEM_ID] [char](32) NULL,
[EVENT_TYPE] [varchar](14) NULL,
[PERIOD] [varchar](20) NULL,
[ITEM_NAME] [varchar](20) NULL,
[START_DATETIME] [datetime] NULL,
[END_DATETIME] [datetime] NULL,
[VAL1] [numeric](28, 12) NULL,
[VAL2] [numeric](28, 12) NULL,
[VAL3] [numeric](28, 12) NULL
)
go
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '12/30/2013', '12/30/2013',1 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '12/31/2013', '12/31/2013',2 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/1/2014', '1/1/2014', 3 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/2/2014', '1/2/2014', 4 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/3/2014', '1/3/2014', 5 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/4/2014', '1/4/2014', 6 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/5/2014', '1/5/2014', 7 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/6/2014', '1/6/2014', 8 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/7/2014', '1/7/2014', 9 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/8/2014', '1/8/2014', 10 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/9/2014', '1/9/2014', 11 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/10/2014', '1/10/2014', 12 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/11/2014', '1/11/2014', 13 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/12/2014', '1/12/2014', 14 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/13/2014', '1/13/2014', 15 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/14/2014', '1/14/2014', 16 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/15/2014', '1/15/2014', 17 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/16/2014', '1/16/2014', 18 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/17/2014', '1/17/2014', 19 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/18/2014', '1/18/2014', 20 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/19/2014', '1/19/2014', 21 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/20/2014', '1/20/2014', 22 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/21/2014', '1/21/2014', 23 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/22/2014', '1/22/2014', 24 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/23/2014', '1/23/2014', 25 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/24/2014', '1/24/2014', 26 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/25/2014', '1/25/2014', 27 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/26/2014', '1/26/2014', 28 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/27/2014', '1/27/2014', 29 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/28/2014', '1/28/2014', 30 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/29/2014', '1/29/2014', 31 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/30/2014', '1/30/2014', 32 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '1/31/2014', '1/31/2014', 33 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/1/2014', '2/1/2014', 34 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/2/2014', '2/2/2014', 35 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/3/2014', '2/3/2014', 36 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/4/2014', '2/4/2014', 37 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/5/2014', '2/5/2014', 38 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/6/2014', '2/6/2014', 39 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/7/2014', '2/7/2014', 40 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/8/2014', '2/8/2014', 41 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/9/2014', '2/9/2014', 42 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/10/2014', '2/10/2014', 43 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/11/2014', '2/11/2014', 44 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/12/2014', '2/12/2014', 45 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/13/2014', '2/13/2014', 46 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/14/2014', '2/14/2014', 47 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/15/2014', '2/15/2014', 48 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/16/2014', '2/16/2014', 49 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/17/2014', '2/17/2014', 50 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/18/2014', '2/18/2014', 51 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/19/2014', '2/19/2014', 52 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/20/2014', '2/20/2014', 53 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/21/2014', '2/21/2014', 54 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/22/2014', '2/22/2014', 55 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/23/2014', '2/23/2014', 56 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/24/2014', '2/24/2014', 57 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/25/2014', '2/25/2014', 58 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/26/2014', '2/26/2014', 59 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/27/2014', '2/27/2014', 60 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '2/28/2014', '2/28/2014', 61 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/1/2014', '3/1/2014', 62 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/2/2014', '3/2/2014', 63 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/3/2014', '3/3/2014', 64 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/4/2014', '3/4/2014', 65 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/5/2014', '3/5/2014', 66 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/6/2014', '3/6/2014', 67 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/7/2014', '3/7/2014', 68 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/8/2014', '3/8/2014', 69 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/9/2014', '3/9/2014', 70 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/10/2014', '3/10/2014', 71 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/11/2014', '3/11/2014', 72 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/12/2014', '3/12/2014', 73 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/13/2014', '3/13/2014', 74 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/14/2014', '3/14/2014', 75 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/15/2014', '3/15/2014', 76 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/16/2014', '3/16/2014', 77 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/17/2014', '3/17/2014', 78 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/18/2014', '3/18/2014', 79 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/19/2014', '3/19/2014', 80 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/20/2014', '3/20/2014', 81 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/21/2014', '3/21/2014', 82 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/22/2014', '3/22/2014', 83 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/23/2014', '3/23/2014', 84 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/24/2014', '3/24/2014', 85 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/25/2014', '3/25/2014', 86 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/26/2014', '3/26/2014', 87 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/27/2014', '3/27/2014', 88 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/28/2014', '3/28/2014', 89 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/29/2014', '3/29/2014', 90 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/30/2014', '3/30/2014', 91 )
INSERT [dbo].[ITEM_VOL] ([EVENT_GROUP_ID], [ITEM_ID], [EVENT_TYPE], [PERIOD],[ITEM_NAME] , [START_DATETIME],[END_DATETIME], [VAL1]) VALUES('1','20607ddfa3a445ceb1fb03e76c8620e6','PROD_TEST', 'EVENT' , 'FACILITY', '3/31/2014', '3/31/2014', 92 )
GO
;WITH rn_cte
AS (SELECT Row_number()
OVER (
partition BY Month(end_datetime)
ORDER BY end_datetime ) AS rn_month,
Row_number()
OVER (
partition BY Datepart(wk, end_datetime)
ORDER BY end_datetime ) AS rn_week,
Row_number()
OVER (
partition BY Datepart(qq, end_datetime)
ORDER BY end_datetime ) AS rn_quarter,
Row_number()
OVER (
partition BY Datepart(year, end_datetime)
ORDER BY end_datetime ) AS rn_year,
Row_number()
OVER (
ORDER BY end_datetime ) AS rn_cumulative,
end_datetime AS dateok,
Cast(val1 AS INT) dailydata
FROM [item_vol]),
rec_cte
AS (SELECT *,
dailydata AS week_cumulative,
dailydata AS month_cumulative,
dailydata AS quarter_cumulative,
dailydata AS overall_cumulative
FROM rn_cte
WHERE rn_cumulative = 1
UNION ALL
SELECT a.*,
CASE
WHEN a.rn_week = 1 THEN a.dailydata
WHEN a.rn_week <> 1 THEN a.dailydata + b.week_cumulative
END AS week_cumulative,
CASE
WHEN a.rn_month = 1 THEN a.dailydata
WHEN a.rn_month <> 1 THEN a.dailydata + b.month_cumulative
END AS month_cumulative,
CASE
WHEN a.rn_quarter = 1 THEN a.dailydata
WHEN a.rn_quarter <> 1 THEN a.dailydata + b.quarter_cumulative
END AS quarter_cumulative,
CASE
WHEN a.rn_cumulative = 1 THEN a.dailydata
WHEN a.rn_cumulative <> 1 THEN a.dailydata + b.overall_cumulative
END AS overall_cumulative
FROM rn_cte a
JOIN rec_cte b
ON a.rn_cumulative = b.rn_cumulative + 1)
SELECT dateok,
dailydata,
rn_week,
week_cumulative,
rn_month,
month_cumulative,
rn_quarter,
quarter_cumulative,
rn_cumulative,
overall_cumulative
FROM rec_cte
go