CREATE FUNCTION [dbo].[Cc_Email_20161021] ( @RETE as varchar(1) = '', @CODICE as varchar(6) = '', @NS as int = 0, -- NUMERO SOLLECITI FATTI, @TIPOEMAIL as varchar(19) = '' ) RETURNS varchar(500) AS BEGIN DECLARE @CC_DI_RITORNO as varchar(500) SET @CC_DI_RITORNO = ''; if @TIPOEMAIL = 'PERF' RETURN @CC_DI_RITORNO declare @flag as bit set @flag = 0 DECLARE @PV as varchar(1) SET @PV = ';' declare @flagAM as bit set @flagAM = 0 DECLARE @REF_SEDE as varchar(200) SET @REF_SEDE = '' IF @RETE = 'F' BEGIN SET @REF_SEDE = @REF_SEDE + 'SEIDIREZIONERETE@BANCAFIDEURAM.IT' + @PV; SET @REF_SEDE = @REF_SEDE + 'SEI@BANCAFIDEURAM.IT'; END ELSE IF @RETE = 'S' BEGIN SET @REF_SEDE = @REF_SEDE + 'SEIDIREZIONERETE@SPINVEST.COM' + @PV; SET @REF_SEDE = @REF_SEDE + 'SEI@SPINVEST.COM'; END --dal 2 sollecito coinvolgo la struttura RETE manageriale SELECT @flag = (CASE WHEN (@TIPOEMAIL in ('2_SOLL_NOMIG','2_SOLL_NOASS','3_SOLL_NOMIG','3_SOLL_NOASS','S_SOLL_NOMIG','S_SOLL_NOASS','REVOCA_NOMIG','REVOCA_NOASS')) THEN 1 ELSE 0 END) --dal 3 sollecito coinvolgo l'AM SELECT @flagAM = (CASE WHEN (@TIPOEMAIL in ('3_SOLL_NOMIG','3_SOLL_NOASS','S_SOLL_NOMIG','S_SOLL_NOASS','REVOCA_NOMIG','REVOCA_NOASS')) THEN 1 ELSE 0 END) declare @ritorno as varchar(500) set @ritorno = '' IF(@flag=1) begin --em.rete,em.codice, --em.email select @ritorno = @ritorno + em.email + @PV from ( SELECT rete,rm as codice from c6mart.struttura_rete sr where Rete = @RETE and PB = @CODICE and rm <> pb union all SELECT rete,dm as codice from c6mart.struttura_rete sr where Rete = @RETE and PB = @CODICE and dm <> rm union all SELECT rete,am as codice from c6mart.struttura_rete sr where Rete = @RETE and PB = @CODICE and am <> dm and @flagAM = 1 ) a inner join C6Mart.EMAIL_PB em on a.rete = em.rete and a.codice = em.codice end --dal 3 sollecito coinvolgo anche Direzione ed Assistenza Rete if(@flagAM=1) set @ritorno = @REF_SEDE + @PV + @ritorno RETURN @ritorno --RETURN '@NS=' + cast(@NS as varchar(2)) + '-' + '@flag=' + cast(@flag as varchar(2))+ '-' + '@flagAM=' + cast(@flagAM as varchar(2)) END --BEGIN -- DECLARE @CC_DI_RITORNO as varchar(255) -- SET @CC_DI_RITORNO = @CC; -- IF @RETE = 'F' -- BEGIN -- SET @CC_DI_RITORNO = REPLACE(@CC_DI_RITORNO,'/$EMAIL_DIREZIONE$/','DIREZIONERETE@BANCAFIDEURAM.IT'); -- SET @CC_DI_RITORNO = REPLACE(@CC_DI_RITORNO,'/$EMAIL_ASSISTENZA$/','ASSISTENZARETE@BANCAFIDEURAM.IT'); -- END -- ELSE IF @RETE = 'S' -- BEGIN -- SET @CC_DI_RITORNO = REPLACE(@CC_DI_RITORNO,'/$EMAIL_DIREZIONE$/','DIREZIONERETE@SPINVEST.IT'); -- SET @CC_DI_RITORNO = REPLACE(@CC_DI_RITORNO,'/$EMAIL_ASSISTENZA$/','ASSISTENZARETE@SPINVEST.IT'); -- END -- RETURN @CC_DI_RITORNO --END