CREATE procedure [C6MartPeriodico].[AppRendTabReader_bl]
	@ColumnSql varchar(5000),
	@motivo varchar(5000)
AS
BEGIN
DECLARE @mywhere varchar(4000);
DECLARE @myselect varchar(1000);
DECLARE @mystmt varchar(5000);
SET @myselect = ' SELECT  '+ @ColumnSql;	
SET @mywhere = ' WHERE codice_fiscale in (select codicefiscale FROM [C6StampeCentralizzate].[C6MartPeriodico].[ExcludedList]"
	        		+ "  WHERE	[DescrErr] = '''+@motivo+''')';	
SET @mystmt = @myselect + ' FROM [C6StampeCentralizzate].[C6MartPeriodico].[tabellone] ' + @mywhere ;
EXEC( @mystmt )
END