Print ''
Print '========================================================================='
Print ' Delete all JobResults and Reset ProcessStatus to:N'
Print ' Autor        : J.Feuerstein'
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 = 20

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
