What was left out were all the declares and the declare for the cursor. I have shown it below. I took a working procedure that works fine against the development database (in the PRIMARY filegroup) and ran it against the production database (in a secondary filegroup) One ran for 25 minutes the next ran 10 hours. I am trying to find out why so I am adding the logging.
Thank you very much for helping.
Warm regards,
Hope
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--CREATE PROC dbo.z_pes_sync_pr_input_insert AS
BEGIN
DECLARE @StoredProcedureName VARCHAR(255)
DECLARE @MyErrorMessage VARCHAR(50)
--SET @StoredProcedureName = OBJECT_NAME(@@PROCID)
SET @StoredProcedureName = 'manual testing'
SET @MyErrorMessage = '1-START pr_input insert only '
EXEC tempdb.dbo.z_pes_ErrorLog_Insert @StoredProcedureName, @MyErrorMessage
SET NOCOUNT ON
SET ANSI_NULLS ON
SET ANSI_WARNINGS ON
declare @p_OpCo as integer
declare @p_Loc_No as integer
declare @p_Div_No as integer
declare @p_Pay_Date as datetime
declare @p_Freq as char(1)
declare @p_Pr_No as integer
declare @p_Spare as integer
declare @p_Summ_No as integer
declare @p_Emp_No as integer
declare @p_Item_No as integer
declare @p_Ref_No as integer
declare @p_Check_No as integer
declare @p_Ss_No as integer
declare @p_Wcomp_1 as decimal(8,2)
declare @p_Wcomp_2 as decimal(8,2)
declare @p_Per_Start as datetime
declare @p_Per_End as datetime
declare @p_Bal_No as integer
declare cursor_03 cursor for
select
cast(Loc_No as integer) as Loc_No ,
cast(Div_No as integer) as Div_No ,
cast(Pay_Date as datetime) as Pay_Date ,
cast(Freq as char(1)) as Freq ,
cast(Pr_No as integer) as Pr_No ,
cast(Spare as integer) as Spare ,
cast(Summ_No as integer) as Summ_No ,
cast(Emp_No as integer) as Emp_No ,
cast(Item_No as integer) as Item_No ,
cast(Ref_No as integer) as Ref_No ,
cast(Check_No as integer) as Check_No ,
cast(Ss_No as integer) as Ss_No ,
cast(Wcomp_1 as decimal(8,2)) as Wcomp_1 ,
cast(Wcomp_2 as decimal(8,2)) as Wcomp_2 ,
cast(Per_Start as datetime) as Per_Start ,
cast(Per_End as datetime) as Per_End ,
cast(Bal_No as integer) as Bal_No
from openquery(db032007,'select * from pr_input') pr_input
open cursor_03
SET @MyErrorMessage = 'cursor_03 is open'
EXEC tempdb.dbo.z_pes_ErrorLog_Insert @StoredProcedureName, @MyErrorMessage