-- Schema: C6Staging
-- Stored Procedure: CheckScartiMIFID

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE procedure [C6Staging].[CheckScartiMIFID]
	-- Add the parameters for the stored procedure here
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    /*-- Insert statements for procedure here
	DECLARE @iScarti INT

	SELECT @iScarti = count(rete+codiceFiscale)
	FROM C6STAGING.SPB_SCARTI SPB
	WHERE pacchettoSSIS = 'SPB_MIFID'
select @iScarti
	IF @iScarti > 0
		RAISERROR ('Scarti MIFID presenti.', -- Message text.
               16, -- Severity.
               1 -- State.
               );
	*/

	declare @iScarti INT

	select @iscarti = 
		count(*) 
		from 
			c6mart.vContrattiMigrati n 
		left join
			C6STAGING.SPB_MIFID m 
		on	
			n.rete = m.rete and
			n.cod_fiscale = m.codiceFiscale
		where
			m.rete is null
				
	if @iScarti > 0
		RAISERROR ('Scarti MIFID presenti.', -- Message text.
               16, -- Severity.
               1 -- State.
               );


END



