-- Schema: C6Mart
-- Stored Procedure: DM_GER_PROMOTORI

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE procedure [C6Mart].[DM_GER_PROMOTORI]
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	DECLARE @ID_ELAB INT
	SET @ID_ELAB = C6MART.GETIDELAB()

    -- Insert statements for procedure here
	TRUNCATE TABLE C6MART.GER_PROMOTORI

	SELECT DISTINCT

---- INFO TABELLA PER GESTIONE ERRORE
--		'GER_PROMOTORI' AS TABLENAME,
--		'RETE - ID_PROMOTORE' AS KEYCOLUMN,
--		SPB_NAC.CODICERETE + ' - ' + SPB_NAC.CODICEAGENTE AS KEYVALUE,
---- FINE INFO TABELLA PER GESTIONE ERRORE

		SPB_NAC.CODICERETE AS RETE,
		SPB_NAC.CODICEAGENTE AS ID_PROMOTORE,
		SPB_NAC.LIVELLONELLAGERARCHIA AS LIVELLO,
		SPB_NAC.CODICEMANAGER AS ID_MANAGER,
		SPB_NAC.SUBORDINATI AS  SUBORDINATI,
		@ID_ELAB AS ID_ELAB,
		'D' AS TIPO_ELAB
	FROM C6STAGING.SPB_NAC

END



