Print ''
Print '========================================================================='
Print ' Delete all JobResults and Reset ProcessStatus to:N'
Print ' Autor        : #New: 04.03.2017?J.Fes'
Print ' Autor        : #LUp: 26.11.2025/J.Fes set @ProcStatColsN = from 20 to 40'
Print '========================================================================='


use [#DB_N#]

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

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

  set @ExecuteMsgRf='Reset Process Status:[ProcStateColRf] 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
