CREATE PROCEDURE [dbo].[MIGRAZIONEPDF2]
AS
BEGIN
    -- SELECT max(id) FROM seireport.dbo.repositoryMetadati
    -- SELECT * FROM migrareport
    -- UPDATE migrareport SET dt = null
    SELECT TOP 100
		 m.id as idPdf
		,m.cod_agente as CodicePB
		,m.note as note
		,m.dataGenerazione as dtCreazione
		,m.codicecontratto as codicecontratto
		,case when m.repository=4 then 'A' else 'O' end as idArchivio
		,case when m.tipoReport=1 and m.rete = 'F' then 1
			 when m.tipoReport= 1 and m.rete = 'S' then 2	
			 when m.tipoReport = 3 and m.rete = 'F' then 3
			 when m.tipoReport= 3 and m.rete = 'S' then 4
			 when m.tipoReport=4 and m.rete = 'F' then 5
			 when m.tipoReport= 4 and m.rete = 'S' then 6 
			 else -1 end as idModello
		, r.chiaveclientepb
		,  null as [image] --F.FILEREPORT as [image]
   into #app
   FROM repositoryMetadati m JOIN  migrareport r ON m.id = r.id
		--LEFT JOIN REPORTFISICO F ON F.Identificativo = M.idInrepository
   WHERE r.DT IS NULL 
   update migrareport set dt = getdate() where id in (select idPdf from #app)
   select * from #app
END