if db_id('UPDATE') is null CREATE DATABASE UPDATE
go
USE UPDATE
go
IF EXISTS(SELECT TABLE_NAME FROM UPDATE.INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '_cdm_') DROP TABLE dbo._cdm_
go
CREATE TABLE dbo._cdm_ (ID INT IDENTITY(0,1) PRIMARY KEY, EVENTO VARCHAR(4000),DATA_ORA DATETIME)
go
INSERT INTO dbo._cdm_ (EVENTO, DATA_ORA) VALUES ('Inizio elaborazione', '2022-03-25T13:43:33')
INSERT INTO dbo._cdm_ (EVENTO, DATA_ORA) VALUES ('Creazione dump', '2022-03-25T13:43:33')
go
INSERT INTO dbo._cdm_ (EVENTO, DATA_ORA) VALUES ('Esecuzione dump', GetDate())
go
IF EXISTS(SELECT TABLE_NAME FROM UPDATE.INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'ACDVLZ_01') DROP TABLE dbo.ACDVLZ_01
CREATE TABLE dbo.ACDVLZ_01(ID_AZI varchar(2),[CODLIS] int,[CODART] varchar(015),[ANNATA] int,[PREZZO] decimal(012,5))
go
INSERT INTO dbo._cdm_ (EVENTO, DATA_ORA) VALUES ('Esecuzione dump: popolamento tabella ACDVLZ', GetDate())
INSERT INTO dbo.ACDVLZ_01 VALUES
('01',1,'050000000000001',0,0.67 )
,('01',1,'1101043101V0000',0,0.98361 )
,('01',1,'1101043101V000S',0,1.06557 )
,('01',1,'1101061101V000S',0,0.9836 )
,('01',1,'1101061101Z0000',0,0.8197 )
,('01',1,'1102042101Z0000',0,0.90164 )
,('01',1,'1103042101Z0000',0,0.98361 )
,('01',1,'1104042101V000S',0,1.06557 )
,('01',1,'1104042101Z0000',0,1.06557 )
,('01',1,'1105042101Z0000',0,0.90164 )
,('01',1,'1150043101V000S',0,1.06557 )
,('01',1,'1150061001Z0000',0,0.81967 )
,('01',1,'1150061101Z0000',0,0.98361 )
,('01',1,'1154042101Z0000',0,0.81967 )
,('01',1,'1154043001Z000S',0,0.90163 )
,('01',1,'140104210B50010',0,1.63934 )
,('01',1,'140404210B40010',0,3.11475 )
,('01',1,'1420001A0B40010',0,4.09836 )
,('01',1,'1420001E0B40010',0,4.91803 )
,('01',1,'1420001E0B60010',0,9.83606 )
,('01',1,'1420021A0B40010',0,3.68852 )
,('01',1,'1420021E0B40001',0,4.50819 )
,('01',1,'145006110B50010',0,1.63934 )
,('01',1,'145104210B40010',0,3.11475 )
,('01',1,'145402510B40010',0,2.04918 )
,('01',1,'145404210B40010',0,2.86885 )
,('01',1,'145404310B50010',0,1.22951 )
,('01',1,'990000008100000',0,2.13115 )
,('01',1,'990000008200000',0,2.45902 )
,('01',1,'990000008300000',0,2.95082 )
,('01',1,'990000008400000',0,3.36066 )
,('01',1,'990000008900000',0,3.27868 )
,('01',1,'990000009000000',0,2.13115 )
,('01',1,'990000009200000',0,0.81967 )
,('01',1,'990000009300000',0,0.81967 )
,('01',1,'990000009700000',0,4.09836 )
,('01',1,'990000009800000',0,8.19672 )
,('01',1,'BT570451BT40021',0,2.87 )
,('01',1,'GR0000010B00009',0,22 )
,('01',1,'GR0300000B3002N',0,13.5 )
,('01',2,'1101043101V0000',0,0.88526 )
,('01',2,'1101043101V000S',0,0.95901 )
,('01',2,'1101061101V000S',0,0.88524 )
,('01',2,'1101061101Z0000',0,0.7377 )
,('01',2,'1150043101V000S',0,0.95901 )
,('01',2,'1150061001Z0000',0,0.66393 )
,('01',2,'1150061101Z0000',0,0.88525 )
,('01',2,'1154042101Z0000',0,0.7377 )
,('01',2,'1154043001Z000S',0,0.81147 )
,('01',2,'140100030B30000',0,7.37705 )
,('01',2,'140204510B40020',0,2.58197 )
,('01',2,'140204610B40011',0,2.58197 )
,('01',2,'140404210B40010',0,2.80327 )
,('01',2,'1420001A0B40010',0,3.68852 )
,('01',2,'1420001E0B40010',0,4.42622 )
,('01',2,'1420001E0B60010',0,8.85245 )
,('01',2,'1420021A0B40010',0,3.31967 )
,('01',2,'1420021E0B40001',0,4.05737 )
,('01',2,'1420021E0B40002',0,4.42622 )
,('01',2,'1430061D0B40010',0,3.31967 )
,('01',2,'145000510B40010',0,5.90164 )
,('01',2,'145104210B40010',0,2.80327 )
,('01',2,'145404210B40010',0,2.58197 )
,('01',2,'990000008100000',0,2.13115 )
,('01',2,'990000008200000',0,2.45902 )
,('01',2,'990000008300000',0,2.95082 )
,('01',2,'990000008400000',0,3.36066 )
,('01',2,'990000008900000',0,3.27868 )
,('01',2,'990000009000000',0,2.13115 )
,('01',2,'990000009200000',0,0.81967 )
,('01',2,'990000009300000',0,0.81967 )
,('01',2,'990000009700000',0,4.09836 )
,('01',2,'990000009800000',0,8.19672 )
,('01',2,'BT570271BT40021',0,2.58197 )
,('01',303,'1420001C0B40411',0,2.3875 )
,('01',303,'1420001DBT40411',0,2.3875 )
,('01',303,'1420001EBT40411',0,2.3875 )
,('01',303,'1420001FBT40411',0,2.3875 )
,('01',303,'1420022EBT4082F',0,1.675 )
,('01',313,'1420001E0B40331',0,1.86 )
,('01',313,'1420001E0B40332',0,1.86 )
,('01',313,'1420001E0B40333',0,1.86 )
,('01',313,'1420021E0B40331',0,1.5675 )
,('01',313,'1420021E0B40332',0,1.5675 )
,('01',313,'1420021E0B40333',0,1.5675 )
,('01',313,'1420021E0B40334',0,1.5675 )
,('01',313,'1420021E0B40335',0,1.5675 )
,('01',313,'1420022E0B40331',0,1.5675 )
,('01',313,'1420022E0B40332',0,1.5675 )
,('01',405,'000000000B40021',0,9.59 )
,('01',405,'000000000B40022',0,31.33 )
,('01',405,'000000000B40023',0,51.61 )
,('01',405,'110106110000021',0,1.05 )
,('01',405,'110106110000022',0,1.32 )
,('01',405,'110106110000023',0,2.34 )
,('01',405,'110106110100001',0,1.13 )
,('01',405,'11100441010002N',0,1.13 )
,('01',405,'113304400100021',0,1.25 )
,('01',405,'115006110100011',0,1.11 )
,('01',405,'115006110100021',0,1.13 )
go
INSERT INTO dbo.ACDVLZ_01 VALUES
('01',405,'115006110100022',0,1.25 )
,('01',405,'115104510100021',0,1.13 )
,('01',405,'115404510100022',0,1.01 )
,('01',405,'11570441010002N',0,2.34 )
,('01',405,'130802710B40021',0,2.8 )
,('01',405,'140404210B40010',0,2.96 )
,('01',405,'1420001E0B40010',0,4.75 )
,('01',405,'1420001E0B60010',0,10.6 )
,('01',405,'1420021A0B40010',0,3.5 )
,('01',405,'1420021E0B40001',0,4.28 )
,('01',405,'145104210B40010',0,2.96 )
,('01',405,'145404210B40010',0,2.72 )
,('01',405,'990000008900000',0,2.46 )
,('01',405,'990000009100000',0,0.41 )
,('01',405,'990000009200000',0,0.82 )
,('01',405,'990000009300000',0,0.82 )
,('01',405,'BB020441BB7002N',0,6.7 )
,('01',405,'BB540451BB70021',0,6.7 )
,('01',405,'BT00000BB14002A',0,2.49 )
,('01',405,'BT0106110B30021',0,7.46 )
,('01',405,'BT050271B24002N',0,2.18 )
,('01',405,'BT060291B240021',0,2.57 )
,('01',405,'BT10044AB240021',0,2.26 )
,('01',405,'BT200221B34003N',0,3.04 )
,('01',405,'BT30000BB14002A',0,3.82 )
,('01',405,'BT310271B24002N',0,2.18 )
,('01',405,'BT310271B24003N',0,4.36 )
,('01',405,'BT32028HB14002A',0,3.89 )
,('01',405,'BT520271B24002N',0,2.41 )
,('01',405,'BT530271B24002N',0,2.26 )
,('01',405,'BT530271B24003N',0,5.76 )
,('01',405,'BT540271B24002N',0,2.18 )
,('01',405,'BT570451BT40021',0,2.72 )
,('01',405,'BT58044AB24002N',0,2.65 )
,('01',405,'BTCH000BB14000B',0,23.36 )
,('01',405,'BTCH000DB14000A',0,21.02 )
,('01',405,'FS01061A838002A',0,1.95 )
,('01',405,'GR0000010B00001',0,10.12 )
,('01',405,'GR0000010B00002',0,10.36 )
,('01',405,'GR0000010B00003',0,11.14 )
,('01',405,'GR0000010B00004',0,12.07 )
,('01',405,'GR0000010B00005',0,12.07 )
,('01',405,'GR0000010B00006',0,11.14 )
,('01',405,'GR0000010B00008',0,11.5 )
,('01',405,'GR010000B30002N',0,11.88 )
,('01',405,'GR0200000B3002N',0,8.95 )
,('01',407,'000000000B40021',0,9.39 )
,('01',407,'000000000B40022',0,30.67 )
,('01',407,'000000000B40023',0,50.52 )
,('01',407,'110106110000021',0,1.03 )
,('01',407,'110106110000022',0,1.3 )
,('01',407,'110106110000023',0,2.29 )
,('01',407,'110106110100001',0,1.1 )
,('01',407,'11100441010002N',0,1.1 )
,('01',407,'113304400100021',0,1.22 )
,('01',407,'115006110100011',0,1.14 )
,('01',407,'115006110100021',0,1.1 )
,('01',407,'115006110100022',0,1.22 )
,('01',407,'115104510100021',0,1.1 )
,('01',407,'115404510100022',0,0.99 )
,('01',407,'11570441010002N',0,2.29 )
,('01',407,'130802710B40021',0,2.74 )
,('01',407,'140404210B40010',0,2.9 )
,('01',407,'1420001E0B40010',0,4.65 )
,('01',407,'1420001E0B60010',0,10.59 )
,('01',407,'1420021A0B40010',0,3.43 )
,('01',407,'1420021E0B40001',0,4.19 )
,('01',407,'145104210B40010',0,2.9 )
,('01',407,'145404210B40010',0,2.67 )
,('01',407,'990000008900000',0,2.46 )
,('01',407,'990000009100000',0,0.41 )
,('01',407,'990000009200000',0,0.82 )
,('01',407,'990000009300000',0,0.82 )
,('01',407,'BB020441BB7002N',0,6.56 )
,('01',407,'BB540451BB70021',0,6.56 )
,('01',407,'BT00000BB14002A',0,2.44 )
,('01',407,'BT0106110B30021',0,7.32 )
,('01',407,'BT060291B240021',0,2.52 )
,('01',407,'BT10044AB240021',0,2.21 )
,('01',407,'BT200221B34003N',0,2.97 )
,('01',407,'BT30000BB14002A',0,3.73 )
,('01',407,'BT310271B24002N',0,2.13 )
,('01',407,'BT310271B24003N',0,4.27 )
,('01',407,'BT32028HB14002A',0,3.81 )
,('01',407,'BT50000BB14002A',0,3.51 )
,('01',407,'BT520271B24002N',0,2.36 )
,('01',407,'BT530271B24002N',0,2.21 )
,('01',407,'BT530271B24003N',0,5.64 )
,('01',407,'BT570451BT40021',0,2.67 )
,('01',407,'BT58044AB24002N',0,2.59 )
,('01',407,'BTCH000BB14000B',0,22.87 )
,('01',407,'BTCH000DB14000A',0,20.58 )
,('01',407,'FS01061A838002A',0,1.91 )
,('01',407,'GR0000010B00001',0,9.91 )
,('01',407,'GR0000010B00002',0,10.14 )
,('01',407,'GR0000010B00003',0,10.9 )
,('01',407,'GR0000010B00004',0,11.82 )
,('01',407,'GR0000010B00005',0,11.82 )
,('01',407,'GR0000010B00006',0,10.9 )
,('01',407,'GR010000B30002N',0,11.05 )
go
INSERT INTO dbo.ACDVLZ_01 VALUES
('01',407,'GR0200000B3002N',0,8.77 )
,('01',410,'000000000B40021',0,9.09 )
,('01',410,'000000000B40022',0,29.68 )
,('01',410,'000000000B40023',0,48.89 )
,('01',410,'110106110000021',0,1 )
,('01',410,'110106110000022',0,1.25 )
,('01',410,'110106110000023',0,2.21 )
,('01',410,'110106110100001',0,1.07 )
,('01',410,'11100441010002N',0,1.07 )
,('01',410,'113304400100021',0,1.18 )
,('01',410,'115006110100011',0,1.11 )
,('01',410,'115006110100021',0,1.07 )
,('01',410,'115006110100022',0,1.18 )
,('01',410,'115104510100021',0,1.07 )
,('01',410,'115404510100022',0,0.96 )
,('01',410,'11570441010002N',0,2.21 )
,('01',410,'130802710B40021',0,2.66 )
,('01',410,'140404210B40010',0,2.8 )
,('01',410,'1420001E0B40010',0,4.5 )
,('01',410,'1420001E0B60010',0,10.03 )
,('01',410,'1420021A0B40010',0,3.32 )
,('01',410,'1420021E0B40001',0,4.06 )
,('01',410,'145104210B40010',0,2.8 )
,('01',410,'990000008900000',0,2.46 )
,('01',410,'990000009100000',0,0.41 )
,('01',410,'990000009200000',0,0.82 )
,('01',410,'990000009300000',0,0.82 )
,('01',410,'BB020441BB7002N',0,6.34 )
,('01',410,'BB540451BB70021',0,6.34 )
,('01',410,'BT00000BB14002A',0,2.36 )
,('01',410,'BT0106110B30021',0,7.08 )
,('01',410,'BT060291B240021',0,2.43 )
,('01',410,'BT10044AB240021',0,2.14 )
,('01',410,'BT200221B34003N',0,2.88 )
,('01',410,'BT30000BB14002A',0,3.61 )
,('01',410,'BT310271B24002N',0,2.07 )
,('01',410,'BT310271B24003N',0,4.13 )
,('01',410,'BT32028HB14002A',0,3.69 )
,('01',410,'BT50000BB14002A',0,3.39 )
,('01',410,'BT520271B24002N',0,2.29 )
,('01',410,'BT530271B24002N',0,2.14 )
,('01',410,'BT530271B24003N',0,5.46 )
,('01',410,'BT58044AB24002N',0,2.51 )
,('01',410,'BTCH000BB14000B',0,22.13 )
,('01',410,'BTCH000DB14000A',0,19.92 )
,('01',410,'FS01061A838002A',0,1.84 )
,('01',410,'GR0000010B00001',0,9.59 )
,('01',410,'GR0000010B00002',0,9.81 )
,('01',410,'GR0000010B00003',0,10.55 )
,('01',410,'GR0000010B00004',0,11.43 )
,('01',410,'GR0000010B00005',0,11.43 )
,('01',410,'GR0000010B00006',0,10.55 )
,('01',410,'GR010000B30002N',0,10.7 )
,('01',410,'GR0200000B3002N',0,8.48 )
,('01',411,'110106110100001',0,0.9 )
,('01',411,'115006110100021',0,0.95 )
,('01',411,'115404510100022',0,0.85 )
,('01',412,'110106110100001',0,0.85 )
,('01',412,'115006110100021',0,0.85 )
,('01',412,'115404510100022',0,0.75 )
go
INSERT INTO dbo._cdm_ (EVENTO, DATA_ORA) VALUES ('Esecuzione dump: creazione br-indici tabella ACDVLZ_01', GetDate())
BEGIN TRY
CREATE UNIQUE INDEX KEY01 ON dbo.ACDVLZ_01 (ID_AZI,CODLIS,CODART,ANNATA)
END TRY
BEGIN CATCH
INSERT INTO dbo._cdm_ SELECT ERROR_MESSAGE(), GETDATE()
END CATCH;
BEGIN TRY
CREATE INDEX KEY02 ON dbo.ACDVLZ_01 (ID_AZI,CODART,ANNATA,CODLIS)
END TRY
BEGIN CATCH
INSERT INTO dbo._cdm_ SELECT ERROR_MESSAGE(), GETDATE()
END CATCH;
go
INSERT INTO dbo._cdm_ (EVENTO, DATA_ORA) VALUES ('Fine elaborazione', GetDate())
go
