
/*------ ATD 320814 ------*/
IF NOT EXISTS (SELECT 1 FROM SYSCOLUMNS C JOIN SYSOBJECTS T ON C.ID = T.ID AND T.XTYPE = 'U'
				WHERE T.NAME = 'TabTranFat' AND C.NAME = 'TipoTransportador')
	ALTER TABLE TabTranFat ADD TipoTransportador NUMERIC(1,0) NOT NULL DEFAULT 0
go

IF NOT EXISTS (SELECT 1 FROM SYSCOLUMNS C JOIN SYSOBJECTS T ON C.ID = T.ID AND T.XTYPE = 'U'
				WHERE T.NAME = 'ManifestoCargaDocumento' AND C.NAME = 'IndReentrega')
	ALTER TABLE ManifestoCargaDocumento ADD IndReentrega NUMERIC(1,0) NOT NULL DEFAULT 0
go

IF NOT EXISTS (SELECT 1 FROM SYSCOLUMNS C JOIN SYSOBJECTS T ON C.ID = T.ID AND T.XTYPE = 'U'
				WHERE T.NAME = 'ManifestoCarga' AND C.NAME = 'CodigoChave')
	ALTER TABLE ManifestoCarga ADD CodigoChave NUMERIC(8,0) NOT NULL DEFAULT 0
go

UPDATE MANIFESTOCARGA
	SET CODIGOCHAVE = CAST(SUBSTRING(CHAVEACESSO,36,8) AS NUMERIC(8))
	WHERE CHAVEACESSO != '' AND CODIGOCHAVE = 0 AND LEN(CHAVEACESSO) = 44
go
