INSERT INTO ClaseTar (IdClase,NomClase,Inactivo)
VALUES ('BIP','BASE IVA INGRESO AL PRODUCTOR',0)
INSERT INTO ClaseTar (IdClase,NomClase,Inactivo)
VALUES ('IVP','TARIFA DE IVA INGRESO AL PRODUCTOR',0)
GO
INSERT INTO ClaseSub (IdClase,NomClase,Inactivo)
VALUES ('0027','IVA INGRESO AL PRODUCTOR',0)
GO
ALTER TABLE SubGrupos ADD CdTarIvp VARCHAR(4)
GO

BEGIN TRANSACTION; 
GO
ALTER TABLE Trn_OComb ADD VrIvaIngProd MONEY
GO
CREATE NONCLUSTERED INDEX [IX_Trn_OCombBaseIvaIgp] ON Trn_OComb
(
	[VrIvaIngProd] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
DECLARE @i INT=1
WHILE( @i <= (select (count(*)/10000)+1 from Trn_OComb) )
  BEGIN
      UPDATE TOP(10000) Trn_OComb SET VrIvaIngProd = 0 WHERE VrIvaIngProd is null
      SET @i=@i + 1
  END
GO
DROP INDEX [IX_Trn_OCombBaseIvaIgp] ON Trn_OComb
GO
ALTER TABLE Trn_OComb ALTER COLUMN VrIvaIngProd MONEY NOT NULL
GO
COMMIT TRANSACTION; 
GO

BEGIN TRANSACTION; 
GO
ALTER TABLE Trn_Opedido ADD BaseIvaIgp MONEY,VrIvaIngProd MONEY
GO
CREATE NONCLUSTERED INDEX [IX_Trn_OpedidoBaseIvaIgp] ON Trn_Opedido
(
	[BaseIvaIgp] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_Trn_OpedidoVrIvaIngProd] ON Trn_Opedido
(
	[VrIvaIngProd] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
DECLARE @i INT=1
WHILE( @i <= (select (count(*)/10000)+1 from Trn_Opedido) )
  BEGIN
      UPDATE TOP(10000) Trn_Opedido SET BaseIvaIgp = 0 WHERE BaseIvaIgp is null
      UPDATE TOP(10000) Trn_Opedido SET VrIvaIngProd = 0 WHERE VrIvaIngProd is null
      SET @i=@i + 1
  END
GO
DROP INDEX [IX_Trn_OpedidoBaseIvaIgp] ON Trn_Opedido
GO
DROP INDEX [IX_Trn_OpedidoVrIvaIngProd] ON Trn_Opedido
GO
ALTER TABLE Trn_Opedido ALTER COLUMN BaseIvaIgp MONEY NOT NULL
GO
ALTER TABLE Trn_Opedido ALTER COLUMN VrIvaIngProd MONEY NOT NULL
GO
COMMIT TRANSACTION; 
GO

BEGIN TRANSACTION; 
GO
ALTER TABLE Trn_DevFcr ADD BaseIvaIgp MONEY, VrIvaIngProd MONEY
GO
CREATE NONCLUSTERED INDEX [IX_Trn_DevFcrBaseIvaIgp] ON Trn_DevFcr
(
	[BaseIvaIgp] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_Trn_DevFcrVrIvaIngProd] ON Trn_DevFcr
(
	[VrIvaIngProd] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
DECLARE @i INT=1
WHILE( @i <= (select (count(*)/10000)+1 from Trn_DevFcr) )
  BEGIN
      UPDATE TOP(10000) Trn_DevFcr SET BaseIvaIgp = 0 WHERE BaseIvaIgp is null
      UPDATE TOP(10000) Trn_DevFcr SET VrIvaIngProd = 0 WHERE VrIvaIngProd is null
      SET @i=@i + 1
  END
GO
DROP INDEX [IX_Trn_DevFcrBaseIvaIgp] ON Trn_DevFcr
GO
DROP INDEX [IX_Trn_DevFcrVrIvaIngProd] ON Trn_DevFcr
GO
ALTER TABLE Trn_DevFcr ALTER COLUMN BaseIvaIgp MONEY NOT NULL
GO
ALTER TABLE Trn_DevFcr ALTER COLUMN VrIvaIngProd MONEY NOT NULL
GO
COMMIT TRANSACTION; 
GO

BEGIN TRANSACTION; 
GO
ALTER TABLE Trn_Facturas ADD BaseIvaIgp MONEY,VrIvaIngProd MONEY
GO
CREATE NONCLUSTERED INDEX [IX_Trn_FacturasBaseIvaIgp] ON Trn_Facturas
(
	[BaseIvaIgp] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_Trn_FacturasVrIvaIngProd] ON Trn_Facturas
(
	[VrIvaIngProd] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
DECLARE @i INT=1
WHILE( @i <= (select (count(tipDoc)/10000)+1 from Trn_Facturas) )
  BEGIN
      UPDATE TOP(10000) Trn_Facturas SET BaseIvaIgp = 0 WHERE BaseIvaIgp is null
      UPDATE TOP(10000) Trn_Facturas SET VrIvaIngProd = 0 WHERE VrIvaIngProd is null
      SET @i=@i + 1
  END
GO
DROP INDEX [IX_Trn_FacturasBaseIvaIgp] ON Trn_Facturas
GO
DROP INDEX [IX_Trn_FacturasVrIvaIngProd] ON Trn_Facturas
GO
ALTER TABLE Trn_Facturas ALTER COLUMN BaseIvaIgp MONEY NOT NULL
GO
ALTER TABLE Trn_Facturas ALTER COLUMN VrIvaIngProd MONEY NOT NULL
GO
COMMIT TRANSACTION; 
GO

BEGIN TRANSACTION; 
GO
ALTER TABLE tm_Kdex ADD tmBaseIvp MONEY,tmTarifaIvp DECIMAL(14,4),tmIvaIngProd MONEY
GO
CREATE NONCLUSTERED INDEX [IX_tm_KdexBaseIvaIgp] ON tm_Kdex
(
	[tmBaseIvp] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_tm_KdexTarifaIvp] ON tm_Kdex
(
	[tmTarifaIvp] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_tm_KdexIvaIngProd] ON tm_Kdex
(
	[tmIvaIngProd] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
DECLARE @i INT=1
WHILE( @i <= (select (count(*)/10000)+1 from tm_Kdex) )
  BEGIN
      UPDATE TOP(10000) tm_Kdex SET tmBaseIvp = 0 WHERE tmBaseIvp is null
      UPDATE TOP(10000) tm_Kdex SET tmTarifaIvp = 0 WHERE tmTarifaIvp is null
	  UPDATE TOP(10000) tm_Kdex SET tmIvaIngProd = 0 WHERE tmIvaIngProd is null
      SET @i=@i + 1
  END
GO
DROP INDEX [IX_tm_KdexBaseIvaIgp] ON tm_Kdex
GO
DROP INDEX [IX_tm_KdexTarifaIvp] ON tm_Kdex
GO
DROP INDEX [IX_tm_KdexIvaIngProd] ON tm_Kdex
GO
ALTER TABLE tm_Kdex ALTER COLUMN tmBaseIvp MONEY NOT NULL
GO
ALTER TABLE tm_Kdex ALTER COLUMN tmTarifaIvp DECIMAL(14,4) NOT NULL
GO
ALTER TABLE tm_Kdex ALTER COLUMN tmIvaIngProd MONEY NOT NULL
GO
COMMIT TRANSACTION; 
GO