if exists (select 1 from syscolumns 
inner join systypes on syscolumns.xtype = systypes.xtype
where id = object_id('EST_PROD_TRANSF_LACRE_IT') and syscolumns.name = 'NR_LACRE' and systypes.name like 'INT')
begin
	EXEC sp_rename 'EST_PROD_TRANSF_LACRE_IT.NR_LACRE', 'NR_LACRE_INT', 'COLUMN';
	ALTER TABLE dbo.EST_PROD_TRANSF_LACRE_IT DROP CONSTRAINT DF_EST_PROD_TRANSF_LACRE_IT_NR_LACRE
end
GO
if not exists(select 1 from syscolumns where id = object_id('EST_PROD_TRANSF_LACRE_IT') and name = 'NR_LACRE')
BEGIN
	ALTER TABLE dbo.EST_PROD_TRANSF_LACRE_IT ADD
		NR_LACRE VARCHAR(150) NULL
	ALTER TABLE dbo.EST_PROD_TRANSF_LACRE_IT ADD CONSTRAINT
		DF_EST_PROD_TRANSF_LACRE_IT_NR_LACRE DEFAULT '' FOR NR_LACRE
END	
GO
declare @Sql varchar(8000)
	set @Sql  = 'UPDATE EST_PROD_TRANSF_LACRE_IT SET 
				 NR_LACRE = convert(bigint,NR_LACRE_INT) WHERE
		(NR_LACRE <> NR_LACRE_INT OR NR_LACRE IS NULL)'

if exists(select 1 from syscolumns where id = object_id('EST_PROD_TRANSF_LACRE_IT') and name = 'NR_LACRE_INT')
BEGIN
	exec (@Sql )
end
GO
ALTER TABLE EST_PROD_TRANSF_LACRE_IT ALTER COLUMN NR_LACRE VARCHAR(150) NOT NULL