-- Schema: C6MartPeriodico -- Stored Procedure: Inizializzazione_tabellone CREATE procedure [C6MartPeriodico].[Inizializzazione_tabellone] AS BEGIN SET NOCOUNT ON; TRUNCATE TABLE [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] --drop index if exists [IDX_TABELLONE_RETE_ACN] on [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] INSERT INTO [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] ([rete_acn] ,[chiave_acn] ,[indirizzo] ,[cap] ,[citta] ,[provincia] ,[nazione] ,[codconf] ,[codman] ,rete ,[chiave_cap] ,[Tipo_cliente] ) select rete,rete+COD_FISCALE,INDIRIZZO,cap,CITTA,PROVINCIA,NAZIONE,codiceContratto,COD_MANDATO,rete, case when COD_FISCALE not like '%@%' then rete+COD_FISCALE+isnull(PIVA_FIDUCIARIA,'')+isnull(COD_MANDATO,'') else rete+isnull(PIVA_FIDUCIARIA,'')+isnull(COD_MANDATO,'') end, case when TIP_CONTRATTO=3 then 'Direct' else 'Sei' end as Tipo_Cliente FROM [C6StampeCentralizzate].[C6StagingPeriodico].[APPO_CONTRATTI] --select * from consuni_periodico.ConsulenzaUnica.dbo.Cliente where codfis is null -- create NONCLUSTERED INDEX [IDX_TABELLONE_RETE_ACN] ON [C6MartPeriodico].[tabellone] --( [chiave_acn] ASC ) --WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] UPDATE [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] set DTTRIM=[C6MartPeriodico].[getTrimestre2](getdate(),0) UPDATE [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] set nome = tab.NOME , cognome = tab.COGNOME ,dtnasci=tab.dtNascita,codfis=tab.codfis from consuni_periodico.ConsulenzaUnica.dbo.Cliente tab inner join [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] as a on substring(a.chiave_acn,2,17)= tab.codfis --select * FROM [C6StampeCentralizzate].[C6StagingPeriodico].[APPO_CONTRATTI] UPDATE [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] set nome = tab.NOME , cognome = tab.COGNOME ,dtnasci=tab.dtNascita,codfis=tab.piva from consuni_periodico.ConsulenzaUnica.dbo.Cliente tab inner join [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] as a on substring(a.chiave_acn,2,17)= tab.piva UPDATE [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] set nome = tab.NOME , cognome = tab.COGNOME ,dtnasci=tab.dtNascita,codfis=tab.piva from consuni_periodico.ConsulenzaUnica.dbo.Cliente tab inner join [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] as a on substring(a.chiave_acn,5,11)= tab.codman where len(chiave_acn) <= 10 --problema nome, cognome if((select COUNT(*) from C6MartPeriodico.tabellone where cognome is null)>0) begin UPDATE [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] set nome = tab.NOME , cognome = tab.COGNOME ,dtnasci=tab.DATA_NASCITA from c6mart.anag_clienti tab inner join [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] as a on a.chiave_acn=tab.rete+tab.cod_fiscale where a.cognome is null end update [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] set cognome =codman+' - '+'SOCIETA'' ITALIANA DI REVISIONE E FIDUCIARIA' ,nome='' where cognome like '%SOCIETA'' ITALIANA DI RE%' UPDATE [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] set codice_agente= w.Codice_Agente,nominativo_pb=trim(w.[Nominativo_ Agente]) ,codice_fiscale=w.CodiceFiscale, freq_monitoraggio=w.Freq_Monitoraggio,freq_diagnosi=w.[Freq_ Diagnosi],data_revoca=try_CONVERT(date,cast(w.Data_Revoca as varchar) ,23), tipo_contratto=w.TipoContratto,tipo_riattivazione=w.TipoRiattivazione,rol_effettiva=isnull(w.ROL,'S') from [dbo].[W6TRCLI] w inner join [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] as a on w.Rete+w.CodiceFiscale=a.chiave_acn --data sottoscrizione (faccio due update per qualcuno che ha delle problematiche, per preferenza meglio il