Hey. So something new has come up.What i see here is that the execution plain is EXACTLY the same but here is what happens. My previous colleague made a solution for running the stored procedures faster. So what he did was creating a stored procedure that would get the details of every incoming main stored procedure and with in a job, loop through every stored procedure and executed it.Here is a cleaner explanation:Job runner - sproc1 , sproc2this would go to:DECLARE @DateFrom as DateTime, @DateTo as DateTimeSET @DateFrom = CONVERT(DATETIME,CONVERT(VARCHAR,DATEADD(hh,-6,getdate()),101))--CONVERT(DATETIME,CONVERT(VARCHAR,GETDATE()-1,101))SET @DateTo = CONVERT(DATETIME,CONVERT(VARCHAR,DATEADD(hh,-6,getdate()+1),101))--CONVERT(DATETIME,CONVERT(VARCHAR,GETDATE(),101))EXEC ZZ_TicketTransactions @DateFrom, @DateTo, '21', 0
The ZZ_TicketTransactions is like this: USE [HO]GO/****** Object: StoredProcedure [dbo].[ZZ_TicketTransactions] Script Date: 21/10/2014 4:24:34 µµ ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER OFFGOALTER PROCEDURE [dbo].[ZZ_TicketTransactions] @DateFrom DATETIME, @DateTo DATETIME, @Cinema VARCHAR(2), @DeleteOtherRecords AS BITASBEGIN IF @DeleteOtherRecords = 1 BEGIN DELETE FROM ZZ_rptTicketsSummary END DECLARE @Parameters AS VARCHAR(1000) DECLARE @ServerName AS VARCHAR(50) SET @Parameters = '''' + convert(varchar,@DateFrom,112)+''','''+convert(varchar,@DateTo,112) +'''' DECLARE MY_CURSOR Cursor FOR SELECT DISTINCT Cinema_strServerName --SELECT DISTINCT REPLACE(REPLACE(Cinema_strServerName,'SSRV2','CSQL') ,'SRV','SQL') From tblCinema C JOIN tblCinema_Operator CO ON C.Cinema_strCode = CO.Cinema_strCode WHERE C.Cinema_strCode = CASE WHEN @Cinema = 'CI' THEN C.Cinema_strCode ELSE @Cinema END AND CinOperator_strOnline = 'Y' Open MY_CURSOR Fetch NEXT FROM MY_CURSOR INTO @ServerName While (@@FETCH_STATUS <> -1) BEGIN EXEC ZZ_execRemoteProcedure @ServerName,'ZZ_TicketTransactions',@Parameters,'ZZ_rptTicketsSummary','ZZ_rptTicketsSummary' Fetch NEXT FROM MY_CURSOR INTO @ServerName END CLOSE MY_CURSOR DEALLOCATE MY_CURSOR IF (@@ERROR <> 0) BEGIN DECLARE @MYERR AS NVARCHAR(MAX) SELECT @MYERR = ERROR_MESSAGE() RAISERROR(@MYERR, 20, 1) RETURN -1 END END
This is the line that runs the actual EXACTLY same stored procedures:EXEC ZZ_execRemoteProcedure @ServerName,'ZZ_TicketTransactions',@Parameters,'ZZ_rptTicketsSummary','ZZ_rptTicketsSummary'ZZ_TicketTransactions is the EXACT SAME SPROC.When i run ZZ_TicketTransactions on the separate databases the execution plan compares EXACTLY the same and the execution time is give or take the same (one db is a little bigger)When i run ZZ_TicketTransactions by using the job that runs the through the sproc (ZZ_execRemoteProcedure) then execution plan is not the same and one DB finishes in 1 second, while the other in 4 minutes. Bear in mind that the 4 minutes is the time that the sprocs will finish if i do not run them through the sproc. So the first sproc that does one second is down 4 minutes without using the ZZ_execRemoteProcedure sproc.