CREATE VIEW [C6MartPeriodico].[vBrsClienteESG]
AS
select * from (
select a.rete,case when isnull(a.codman,'') <> '' then 'FF@' + a.codman 
        when isnull(a.Piva,'') <> '' and isnull(a.codman,'') = '' then a.Piva
       else codicefiscale
end as cod_fiscale,
		[Preferenza_esg_cliente]
      ,[ESG_E]
      ,[ESG_S]
      ,[ESG_G]
      ,[obiettivo_ESG_minimo]
      ,[ESG_Rating]
      ,[ESG_E_perc]
      ,[ESG_S_perc]
      ,[ESG_G_perc]
from c6stagingperiodico.ESG_Metriche_Cliente_IL a
) a