Print ''
Print '========================================================================='
Print ' Delete all JobResults and Reset ProcessStatus to:N'
Print ' #New    : 04.03.2017/J.Feuerstein'
Print ' #LUp    : 13.09.2023/J.Feuerstein'
Print '========================================================================='


use [#DB_N#]

Print 'Database: #DB_N#'
Print '-------------------------------------------------------------------------'


Print 'Delete all Data from Table: JobControl_ObjectsProcessData_tbl'
TRUNCATE TABLE [dbo].[JobControl_ObjectsProcessData_tbl]

declare @ExecuteMsgRf    varchar(max),
        @ExecuteSQLTxtRf varchar(max),
        @ExecuteMsg      varchar(max),
        @ExecuteSQLstr   varchar(max),
        @ColumeName      varchar(max),
        @ColumeNameNr      varchar(max),
        @ProcStatColsN    int,
        @ProcStatColNrCur  int

set @ProcStatColsN = 40

  set @ExecuteMsgRf='Reset Process Status for all P.Groups to:N'
  set @ExecuteSQLTxtRf='UPDATE Objects_tbl SET ProcStateColRf = ''N'' where ((ProcStateColRf <> ''N'') and (ProcStateColRf NOT like ''X%''))'
  Print @ExecuteMsgRf
  print 'via:' + @ExecuteSQLTxtRf
  exec (@ExecuteSQLTxtRf)
  Print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
  set @ProcStatColNrCur = 0
  WHILE @ProcStatColNrCur < @ProcStatColsN
  BEGIN
    set @ProcStatColNrCur = @ProcStatColNrCur + 1
    set @ColumeNameNr=right('00' + convert(nvarchar,@ProcStatColNrCur),2)
    set @ColumeName='ProcStateCol' + @ColumeNameNr
    set @ExecuteMsg    = REPLACE(@ExecuteMsgRf,    'ProcStateColRf',@ColumeName)
    set @ExecuteSQLstr = REPLACE(@ExecuteSQLTxtRf, 'ProcStateColRf',@ColumeName)
    print (@ExecuteMsg)
    print 'via:' + @ExecuteSQLstr
    exec (@ExecuteSQLstr)
    Print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
  END

Print '-------------------------------------------------------------------------'
Print ' End of Script'
Print '-------------------------------------------------------------------------'
GO
GO

