Print ''
Print '----------------------------------------------------'
Print ' JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult'
Print ' FirstRevision: 05.04.2013 15:31'
Print ' Autor        : J.Feuerstein'
Print ' '
Print ' Database Name: #DB_N#'
Print '----------------------------------------------------'
GO

use [#DB_N#]

Print '-'
Print '-- [JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp] -------------------------------------'
If Exists (select Name
           from sysobjects
           where Name = 'JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp' and type = 'P')
Drop Procedure JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp
GO



CREATE PROCEDURE JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp
                                                @ProcStateCol_N  nvarchar(32)  -- Name des Columes
AS
BEGIN


   DECLARE @ExecuteSQLstr nvarchar(max)
   set @ExecuteSQLstr = 'UPDATE dbo.Objects_tbl ' +
                        ' set dbo.Objects_tbl.' + @ProcStateCol_N + '=dbo.JobControl_ObjectsProcessData_tbl.ProcessState' +
                        ' FROM dbo.JobControl_ObjectsProcessData_tbl ' +
                        '  WHERE dbo.JobControl_ObjectsProcessData_tbl.Objects_tbl_ID = dbo.Objects_tbl.Id' +
                        '  AND dbo.JobControl_ObjectsProcessData_tbl.Row_isLastRes = 1 AND' +
                        '      dbo.JobControl_ObjectsProcessData_tbl.ProcessProcStateCol =' + '''' + @ProcStateCol_N + ''''
   print ''
   print '-- Start: - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print '-- Retransfer ProcState: ' + @ProcStateCol_N + ''
   -- print @ExecuteSQLstr
   execute sp_executesql @ExecuteSQLstr
   print '-- End..: - - - - - - - - - - - - - - - - - - - - - - - - - -'
end
Go

 EXECUTE JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp 'ProcStateCol01'
 EXECUTE JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp 'ProcStateCol02'
 EXECUTE JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp 'ProcStateCol03'
 EXECUTE JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp 'ProcStateCol04'
 EXECUTE JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp 'ProcStateCol05'
 EXECUTE JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp 'ProcStateCol06'
 EXECUTE JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp 'ProcStateCol07'
 EXECUTE JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp 'ProcStateCol08'
 EXECUTE JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp 'ProcStateCol09'
 EXECUTE JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp 'ProcStateCol10'
 EXECUTE JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp 'ProcStateColRf'

 -- Final Remove JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp
 Drop Procedure JobMgr_03_ObjectsProcessStatus_ReCover_From_LastProcessResult_temp

Go

Print ''
Print '-------------------------------------------------------------------------'
Print ' Script executed'
Print '-------------------------------------------------------------------------'
GO
