IF NOT EXISTS (SELECT 1 FROM SYSCOLUMNS WHERE ID = OBJECT_ID('EST_TRIB_CONF_GRP') AND name = 'TP_LISTA')
begin
	ALTER TABLE EST_TRIB_CONF_GRP ADD TP_LISTA INT
	ALTER TABLE EST_TRIB_CONF_GRP ADD CONSTRAINT DF_EST_TRIB_CONF_GRP_TP_LISTA DEFAULT 0 FOR TP_LISTA 
end
GO
 
UPDATE EST_TRIB_CONF_GRP SET TP_LISTA  = (SELECT TOP 1 C.TP_LISTA 
										  FROM EST_TRIB_CONF_GRP_CPL C
										  WHERE C.CD_EMP 		= EST_TRIB_CONF_GRP.CD_EMP
												AND C.CD_CTR 	= EST_TRIB_CONF_GRP.CD_CTR)
WHERE TP_LISTA IS NULL												

