IF NOT EXISTS(SELECT 1 FROM SYSCOLUMNS WHERE ID = OBJECT_ID('EST_NF_ENT_DANFE_PROVISORIO_ITENS') AND NAME = 'IND_TOTAL')
begin
	ALTER TABLE dbo.EST_NF_ENT_DANFE_PROVISORIO_ITENS ADD
		IND_TOTAL int NULL

	ALTER TABLE dbo.EST_NF_ENT_DANFE_PROVISORIO_ITENS ADD CONSTRAINT
		DF_EST_NF_ENT_DANFE_PROVISORIO_ITENS_INDTOTAL DEFAULT 1 FOR IND_TOTAL
end
go
UPDATE 
	i 
SET
	i.IND_TOTAL = 1
FROM
	EST_NF_ENT_DANFE_PROVISORIO_ITENS i INNER JOIN EST_NF_ENT_DANFE_PROVISORIO_PENDENTE p ON
	i.CD_CTR  = p.CD_CTR 
WHERE
	i.IND_TOTAL IS NULL

