
CREATE TABLE #TEMP_CREATE (CRIOU BIT)
IF NOT EXISTS (SELECT * FROM SYS.COLUMNS WHERE NAME = 'CD_EST_PROD_CPL_ROBO_LOJA' AND OBJECT_ID = OBJECT_ID('EST_PROD_CPL_ROBO'))
BEGIN
	ALTER TABLE EST_PROD_CPL_ROBO ADD CD_EST_PROD_CPL_ROBO_LOJA INT NULL;
	INSERT INTO #TEMP_CREATE VALUES (1);
END

GO

IF EXISTS (SELECT * FROM #TEMP_CREATE)
BEGIN
	UPDATE EST_PROD_CPL_ROBO SET CD_EST_PROD_CPL_ROBO_LOJA = CD_EST_PROD_CPL_ROBO;
	ALTER TABLE EST_PROD_CPL_ROBO ALTER COLUMN CD_EST_PROD_CPL_ROBO_LOJA INT NOT NULL;
	ALTER TABLE EST_PROD_CPL_ROBO ADD CONSTRAINT DF_EST_PROD_CPL_ROBO_CD_EST_PROD_CPL_ROBO_LOJA DEFAULT 0 FOR CD_EST_PROD_CPL_ROBO_LOJA
END

GO

DROP TABLE #TEMP_CREATE