90 lines
1.9 KiB
Transact-SQL
90 lines
1.9 KiB
Transact-SQL
-- Schema: C6MartPeriodico
|
|
-- Stored Procedure: Popola_S179EmittentiConcentrazioneAlta_20180626
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- =============================================
|
|
-- Author: <>
|
|
-- Create date: <>
|
|
-- Description: <caricamento tabella di generazione S179EmittentiConcentrazioneAlta>
|
|
-- =============================================
|
|
|
|
CREATE procedure [C6MartPeriodico].[Popola_S179EmittentiConcentrazioneAlta_20180626]
|
|
-- Add the parameters for the stored procedure here
|
|
--@Rete char(1),
|
|
--@CodiceFiscale varchar(16)
|
|
AS
|
|
BEGIN
|
|
|
|
DECLARE @DataFineTrim VARCHAR(8)
|
|
SET @DataFineTrim = c6martperiodico.getTrimestre2(getDate(),0)
|
|
|
|
truncate table C6MartPeriodico.TB_S179EmittentiConcentrazioneAlta
|
|
|
|
INSERT INTO C6MartPeriodico.TB_S179EmittentiConcentrazioneAlta
|
|
SELECT
|
|
ce.[RETE]
|
|
,
|
|
case
|
|
when(isnull(ltrim(rtrim(ce.codman)),'') <> '')
|
|
then 'FF@'+ce.codman
|
|
when (isnull(ce.codfis,'') <> '')
|
|
then ce.codfis
|
|
else
|
|
ce.codfis
|
|
end as Codfis
|
|
,1 as Ordine
|
|
,[DESCEMI]
|
|
,
|
|
case
|
|
when upper(asset) = 'O' then [TOTCTV]
|
|
else 0
|
|
end as ObbligazioniControvalore
|
|
,
|
|
case
|
|
when upper(asset) = 'O' then [CONC]
|
|
else 0
|
|
end as ObbligazioniConcentrazione
|
|
,
|
|
case
|
|
when upper(asset) = 'A' then [TOTCTV]
|
|
else 0
|
|
end as AzioniControvalore
|
|
,
|
|
case
|
|
when upper(asset) = 'A' then [CONC]
|
|
else 0
|
|
end as AzioniConcentrazione
|
|
|
|
|
|
FROM [C6StagingPeriodico].[WSEICE] ce
|
|
|
|
inner join [C6StagingPeriodico].[WSEIAN] an
|
|
on ce.rete = an.rete and
|
|
ce.codfis= an.codfis
|
|
|
|
WHERE 1=1
|
|
|
|
and ce.DTTRIM = @DataFineTrim
|
|
and an.concemi = 'N' --estraggo solo quelli che non sono adeguati per concentrazione emittenti sulla wseian
|
|
and ce.flgconc = 'N' -- e solo gli emittenti non adeguati (perché sulla wseice arrivano tutti gli emittenti, adeguati e non)
|
|
|
|
|
|
|
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|