If I run
exec pr_BuscaLog -2, it will run forever (days, without end).
But, if I just copy the query and run it on its own, it runs in seconds.
Updating statistics did not help.
--pr_BuscaLog -1 CREATE procedure [dbo].[pr_BuscaLog] (@qtdDias int) as begin declare @cmd as nvarchar(4000) declare @banco as varchar(100) declare @dataLimite as datetime
UPDATE: When I run
EXEC PR_BUSCALOG, it start to run, and then stops.