-- Stored procedure
-- =============================================
-- Author:		Simone D'Elia
-- Create date: Aprile 2022
-- Description: 
-- =============================================
-- [C6MartPeriodico].[PL_S172PreferenzeESG] 'S', 'VNZGPL53M04L781P'
CREATE procedure [C6Mart].[PL_S181PreferenzeESG_bkp_20240906] --'F','FRLNCT38L47F205E'
 -- Add the parameters for the stored procedure here
 @Rete char(1), 
 @CodiceFiscale varchar(16)
AS
BEGIN
SELECT esg.[rete]
      ,esg.[cod_fiscale]
      ,esg.[Preferenza_esg_cliente]
      ,esg.[ESG_E]
      ,esg.[ESG_S]
      ,esg.[ESG_G]
      ,esg.[obiettivo_ESG_minimo]
      ,esg.[ESG_Rating]
      ,esg.[ESG_E_perc]
      ,esg.[ESG_S_perc]
      ,esg.[ESG_G_perc]
	  ,case when isnull(ind.percESG,'0.00')>=25 and isnull(ind.percESG,'0.00')<50 then 'Almeno pari al 25%'
			when isnull(ind.percESG,'0.00')>=50 and isnull(ind.percESG,'0.00')<75 then 'Almeno pari al 50%'
			when isnull(ind.percESG,'0.00')>=75 then 'Almeno pari al 75%' else 'n.d.' end as Pref_Sost
  FROM [C6StampeCentralizzate].[C6Mart].[BrsClienteESG] esg
  left join c6staging.VAR_ADEGUATEZZA_INDICATORI ind
  on ind.rete=esg.rete and ind.CODICE_FISCALE=esg.cod_fiscale
WHERE 1 = 1
	AND esg.RETE = @Rete
	AND esg.COD_FISCALE = @CodiceFiscale
END