
--------------------------------------
--- COLUNA INDICA_FILIAL_ECOMMERCE ---
--------------------------------------
IF NOT EXISTS
(
	SELECT 1
	FROM   INFORMATION_SCHEMA.COLUMNS
	WHERE  TABLE_NAME = 'LOJAS_VAREJO' AND COLUMN_NAME = 'INDICA_FILIAL_ECOMMERCE'
)
	BEGIN
		ALTER TABLE [DBO].LOJAS_VAREJO ADD INDICA_FILIAL_ECOMMERCE BIT NULL;

		EXEC SP_BINDEFAULT DEFAULT_0, 'DBO.LOJAS_VAREJO.INDICA_FILIAL_ECOMMERCE';

		UPDATE DBO.LOJAS_VAREJO SET  INDICA_FILIAL_ECOMMERCE = 0 WHERE  INDICA_FILIAL_ECOMMERCE IS NULL;

		ALTER TABLE DBO.LOJAS_VAREJO ALTER COLUMN INDICA_FILIAL_ECOMMERCE BIT NOT NULL;
END;
	ELSE
	BEGIN
		IF EXISTS
		(
			SELECT 1
			FROM   INFORMATION_SCHEMA.COLUMNS
			WHERE  TABLE_NAME = 'LOJAS_VAREJO' AND COLUMN_NAME = 'INDICA_FILIAL_ECOMMERCE' AND COLUMN_DEFAULT IS NULL
		)
			BEGIN
				EXEC SP_BINDEFAULT DEFAULT_0, 'DBO.LOJAS_VAREJO.INDICA_FILIAL_ECOMMERCE';
		END;

		UPDATE DBO.LOJAS_VAREJO SET INDICA_FILIAL_ECOMMERCE = 0 WHERE INDICA_FILIAL_ECOMMERCE IS NULL;

		ALTER TABLE DBO.LOJAS_VAREJO ALTER COLUMN INDICA_FILIAL_ECOMMERCE BIT NOT NULL;
END;