CREATE procedure [dbo].[SelezioneCampione_Fc]
   -- @NomeTabella as varchar(50),
    @NomeChiave as varchar(50)
AS
BEGIN
    DECLARE @sql nvarchar(max)
    DECLARE @SQLString NVARCHAR(500)
	DECLARE @ParmDefinition NVARCHAR(500)
	DECLARE @IntVariable INT
	DECLARE @Lastlname varchar(30)
	DECLARE @LastlnameOUT INT
	Set @IntVariable=1
	DECLARE @Giorni int, @i int
	SET @Giorni = 5
	SET @i = 0
--WHILE @IntVariable < 5
--BEGIN
	SET @SQLString = N'select @LastlnameOUT = count(*) from [C6MartPeriodico].[selezionecampione2] WHERE ' + 
            quotename(@NomeChiave) + ' > 0 '
	SET @ParmDefinition = N' @LastlnameOUT varchar(30) OUTPUT'
	EXECUTE sp_executesql @SQLString,@ParmDefinition,@LastlnameOUT=@Lastlname OUTPUT
	IF @Lastlname>0 
	Begin
	   select @Lastlname
	END
	--     SET @sql = N'insert into selezionecampione2_fc (rete,cod_fiscale,'+quotename(@NomeChiave)+') ' + 
	--	' select top 10 rete,cod_fiscale,'+@NomeChiave+' from [C6MartPeriodico].[selezionecampione2] WHERE ' + 
 --           quotename(@NomeChiave) + ' > 0 '  
	--	 EXEC sp_executesql @sql
	--	 set @IntVariable=@IntVariable+1;
	--End  -- IF
--END --While
END