
-- CANCELAMENTOS DE ENTRADAS--------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT 1 FROM SYS.columns WHERE name ='JUSTIFICATIVA' AND OBJECT_NAME(OBJECT_ID) ='EST_NF_ENT_NFE_CANCEL') 
			   ALTER TABLE EST_NF_ENT_NFE_CANCEL ADD  JUSTIFICATIVA VARCHAR(256) NOT NULL DEFAULT '' ;
GO


IF NOT EXISTS (SELECT 1 FROM SYS.columns WHERE name ='CD_LOTE' AND OBJECT_NAME(OBJECT_ID) ='EST_NF_ENT_NFE_CANCEL') 
			   ALTER TABLE EST_NF_ENT_NFE_CANCEL ADD  CD_LOTE INTEGER ;
GO


IF NOT EXISTS (SELECT 1 FROM SYS.columns WHERE name ='NR_AUTORIZADOR' AND OBJECT_NAME(OBJECT_ID) ='EST_NF_ENT_NFE_CANCEL') 
			   ALTER TABLE EST_NF_ENT_NFE_CANCEL ADD  NR_AUTORIZADOR VARCHAR(50) ;
GO


IF NOT EXISTS (SELECT 1 FROM SYS.columns WHERE name ='NR_PROTOCOLO' AND OBJECT_NAME(OBJECT_ID) ='EST_NF_ENT_NFE_CANCEL') 
			   ALTER TABLE EST_NF_ENT_NFE_CANCEL ADD  NR_PROTOCOLO  VARCHAR(50);
GO 


IF NOT EXISTS (SELECT 1 FROM SYS.columns WHERE name ='DS_RETORNO' AND OBJECT_NAME(OBJECT_ID) ='EST_NF_ENT_NFE_CANCEL') 
			   ALTER TABLE EST_NF_ENT_NFE_CANCEL ADD  DS_RETORNO VARCHAR(MAX);
GO




IF NOT EXISTS (SELECT 1 FROM SYS.columns WHERE name ='DT_EVENTO' AND OBJECT_NAME(OBJECT_ID) ='EST_NF_ENT_NFE_CANCEL') 
			   ALTER TABLE EST_NF_ENT_NFE_CANCEL ADD  DT_EVENTO DATETIME ;
GO

-- CANCELAMENTOS DE SAIDA--------------------------------------------------------------------------------------------------

IF NOT EXISTS (SELECT 1 FROM SYS.columns WHERE name ='JUSTIFICATIVA' AND OBJECT_NAME(OBJECT_ID) ='EST_NF_SAI_NFE_CANCEL') 
			   ALTER TABLE EST_NF_SAI_NFE_CANCEL ADD  JUSTIFICATIVA VARCHAR(256) NOT NULL DEFAULT '' ;
GO


IF NOT EXISTS (SELECT 1 FROM SYS.columns WHERE name ='CD_LOTE' AND OBJECT_NAME(OBJECT_ID) ='EST_NF_SAI_NFE_CANCEL') 
			   ALTER TABLE EST_NF_SAI_NFE_CANCEL ADD  CD_LOTE INTEGER ;
GO


IF NOT EXISTS (SELECT 1 FROM SYS.columns WHERE name ='NR_AUTORIZADOR' AND OBJECT_NAME(OBJECT_ID) ='EST_NF_SAI_NFE_CANCEL') 
			   ALTER TABLE EST_NF_SAI_NFE_CANCEL ADD  NR_AUTORIZADOR VARCHAR(50) ;
GO


IF NOT EXISTS (SELECT 1 FROM SYS.columns WHERE name ='NR_PROTOCOLO' AND OBJECT_NAME(OBJECT_ID) ='EST_NF_SAI_NFE_CANCEL') 
			   ALTER TABLE EST_NF_SAI_NFE_CANCEL ADD  NR_PROTOCOLO  VARCHAR(50);
GO 


IF NOT EXISTS (SELECT 1 FROM SYS.columns WHERE name ='DS_RETORNO' AND OBJECT_NAME(OBJECT_ID) ='EST_NF_SAI_NFE_CANCEL') 
			   ALTER TABLE EST_NF_SAI_NFE_CANCEL ADD  DS_RETORNO VARCHAR(MAX);
GO




IF NOT EXISTS (SELECT 1 FROM SYS.columns WHERE name ='DT_EVENTO' AND OBJECT_NAME(OBJECT_ID) ='EST_NF_SAI_NFE_CANCEL') 
			   ALTER TABLE EST_NF_SAI_NFE_CANCEL ADD  DT_EVENTO DATETIME ;
GO
ALTER TABLE [dbo].[EST_NF_SAI_NFE_CANCEL]
DROP CONSTRAINT [FK_EST_NF_SAI_NFE_CANCEL_EST_NFE_LOTE]
GO