Print ''
Print '-------------------------------------------------------------------------'
Print ' using Database: #DB_N#'
Print ' Action        : MaintainDatabase.sql'
Print ' Creation Date : 24.02.2009 /J.Fes'
Print ' LastUpdate    : 06.08.2014 /J.Fes'
Print '-------------------------------------------------------------------------'

use [#DB_N#]

DECLARE @Name nvarchar(64)
DECLARE @ValueCurr nvarchar(max)
DECLARE @ValueDesired nvarchar(max)
DECLARE @ValueCompareStat int
DECLARE @ExecuteSQLstr nvarchar(max)
DECLARE @UpdateDone bit
DECLARE @UpdateCounter int

Print 'Maintain Database: #DB_N# !Start!'
Print '.........................................................................'

-- exec sp_dboption N'#DB_N#', N'read only', N'false'
-- ALTER DATABASE #DB_N# SET READ_WRITE
-- exec sp_dboption N'#DB_N#', N'dbo use', N'false'
-- exec sp_dboption N'#DB_N#', N'single', N'false'
-- exec sp_dboption N'#DB_N#', N'autoshrink', N'true'
-- 30.08.2019/J.Fes A.Becker set to OFF
-- see https://techyaz.com/sql-server/performance-tuning/always-turn-off-database-auto-shrink/
Print 'Database basic settings (#LUp: 30.08.2019) ALTER DATABASE #DB_N# SET AUTO_SHRINK OFF'
ALTER DATABASE #DB_N# SET AUTO_SHRINK OFF

Print '.........................................................................'
Print 'Delete Temp Tables'
if (object_id('zztmpClean1_tbl') is not null)  Drop table zztmpClean1_tbl
if (object_id('zztmpClean2_tbl') is not null)  Drop table zztmpClean2_tbl
if (object_id('zztmpClean3_tbl') is not null)  Drop table zztmpClean3_tbl
if (object_id('zztmpClean4_tbl') is not null)  Drop table zztmpClean4_tbl
if (object_id('zztmpClean5_tbl') is not null)  Drop table zztmpClean5_tbl
-- 14.01.2015/J.Fes removed
-- if (object_id('ReportPageNames_temp_tbl') is not null)  Drop table ReportPageNames_temp_tbl
if (object_id('zztmp_Report_810_ProcessPerHoure') is not null)  Drop table zztmp_Report_810_ProcessPerHoure


set @Name='ObjectsUpdate_ProcessStatus_Mark_LastRes__MaintainDB'
set @ValueCurr=''
set @ValueDesired='2009-02-23-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print 'execute [ObjectsUpdate_ProcessStatus_Mark_LastRes__MaintainDB] Set to Stat:' + @ValueDesired + ' Start!'
   Execute ObjectsUpdate_ProcessStatus_Mark_LastRes__MaintainDB
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print 'execute [ObjectsUpdate_ProcessStatus_Mark_LastRes__MaintainDB] Set to Stat:' + @ValueDesired + ' DONE!'
 end

set @Name='JobControl_ObjectsProcessData_tbl_Update_ProcessResultHasWarning__MaintainDB'
set @ValueCurr=''
set @ValueDesired='2009-07-12-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   set @ExecuteSQLstr='UPDATE JobControl_ObjectsProcessData_tbl set ProcessResultHasWarning = 0 where ProcessResultHasWarning is null'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   execute sp_executesql @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end

set @Name='JobControl_ObjectsProcessData_tbl_Update_ProcessResultLink__MaintainDB'
set @ValueCurr=''
set @ValueDesired='2009-07-12-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   set @ExecuteSQLstr='UPDATE JobControl_ObjectsProcessData_tbl set ProcessResultLink=' + '''' + '''' + ' where ProcessResultLink is null'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   execute sp_executesql @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end


set @Name='JobControlRules_tbl_Update_SelObjectsBy_PFM'
set @ValueCurr=''
set @ValueDesired='2009-10-21-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   set @ExecuteSQLstr='UPDATE JobControlRules_tbl set SelObjectsBy_PFM=1 where SelObjectsBy_PFM is null'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   execute sp_executesql @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end

-- stellt sicher das ObjectUgMaster_PartFamMemName = '' und nicht NULL ist
set @Name='Objects_tbl_Update_ObjectUgMaster_PartFamMemName'
set @ValueCurr=''
set @ValueDesired='2009-10-21-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   set @ExecuteSQLstr='UPDATE Objects_tbl set ObjectUgMaster_PartFamMemName=' + '''' + '''' + ' where ObjectUgMaster_PartFamMemName is null'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   execute sp_executesql @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end

set @Name='Sites_tbl_Update_DbConnectionTimeout'
set @ValueCurr=''
set @ValueDesired='2009-11-02-02'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   set @ExecuteSQLstr='UPDATE Sites_tbl set DbConnectionTimeout=60 where DbConnectionTimeout is null'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   execute sp_executesql @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end



set @Name='Sites_tbl_Update_DbCommandTimeout'
set @ValueCurr=''
set @ValueDesired='2009-11-02-02'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   set @ExecuteSQLstr='UPDATE Sites_tbl set DbCommandTimeout=120 where DbCommandTimeout is null'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   execute sp_executesql @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end


set @Name='Sites_tbl_Update_ImportTc'
set @ValueCurr=''
set @ValueDesired='2010-07-08-04'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'

   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   set @ExecuteSQLstr='UPDATE Sites_tbl set ImportTcIrSearchMethode=1 where ImportTcIrSearchMethode is null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 1/3:->DONE!] ' + @ExecuteSQLstr

   set @ExecuteSQLstr='UPDATE Sites_tbl set ImportTcObjectFs_DPNE=1 where ImportTcObjectFs_DPNE is null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 2/3:->DONE!] ' + @ExecuteSQLstr

   set @ExecuteSQLstr='UPDATE Sites_tbl set ImportTcObjectFs_NE=1 where ImportTcObjectFs_NE is null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 3/3:->DONE!] ' + @ExecuteSQLstr

   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end

-- rem wichtig @Name muss eindeutig sein
set @Name='Sites_tbl_Update_ImportApWithCompCound0AsSp'
set @ValueCurr=''
set @ValueDesired='2010-08-10-02'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   set @ExecuteSQLstr='UPDATE Sites_tbl set ImportApWithCompCound0AsSp=0 where ImportApWithCompCound0AsSp is null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 1/1:->DONE!] ' + @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end


 -- rem wichtig @Name muss eindeutig sein
 set @Name='DataBase_BaseSettings'
 set @ValueCurr=''
 set @ValueDesired='2010-09-03-01'
 EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
 if @ValueCompareStat <> 1
 begin
 IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'#DB_N#')
   BEGIN
      -- neu 2.11.2009 einstellen nicht case sensitive
      ALTER DATABASE [#DB_N#] COLLATE Latin1_General_CI_AS
      Print '------------------------------------------------------------------'
      Print 'OK:Db:#DB_N#'
      Print '    set COLLATE = Latin1_General_CI_AS'

--       --  neu 03.09.2010
--       ALTER DATABASE [#DB_N#] SET ALLOW_SNAPSHOT_ISOLATION ON
--       Print '------------------------------------------------------------------'
--       Print 'OK:Db:#DB_N#'
--       Print '    set allow_snapshot_isolation on (03.09.2010)'
--
--       ALTER DATABASE [#DB_N#] SET READ_COMMITTED_SNAPSHOT ON
--       Print '------------------------------------------------------------------'
--       Print 'OK:Db:#DB_N#'
--       Print '    set READ_COMMITTED_SNAPSHOT ON (03.09.2010)'
      --------------- SQL ---------------
      EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
      print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
   END
 end

 -- rem wichtig @Name muss eindeutig sein
 -- ItemsTbl CleanUp Aktion erstellt 11.01.2011 12:04 J.Fes
 set @Name='ItemsTbl_DeleteAllObjects'
 set @ValueCurr=''
 set @ValueDesired='2011-01-11-01'
 EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
 if @ValueCompareStat <> 1
 begin
  Print '-- [delete function: ItemsTbl_ItemNameRev_GetDS] -------------------------------'
  If Exists (select Name from sysobjects where Name = "ItemsTbl_ItemNameRev_GetDS" and type = "P") Drop Procedure ItemsTbl_ItemNameRev_GetDS

  Print '-- [delete function: ItemsTbl_ItemNameRev_GetId] -------------------------------'
  If Exists (select Name from sysobjects where Name = "ItemsTbl_ItemNameRev_GetId" and type = "P") Drop Procedure ItemsTbl_ItemNameRev_GetId

  Print '-- [delete function: ItemsTblAddDataSet] -------------------------------'
  If Exists (select Name from sysobjects where Name = "ItemsTblAddDataSet" and type = "P") Drop Procedure ItemsTblAddDataSet

--         20: Drop Procedure ItemsTbl_ItemNameRev_GetDS
--      41: Drop Procedure ItemsTbl_ItemNameRev_GetId
--      93: Drop Procedure ItemsTblAddDataSet
  Print '-- [delete View: RefiledItemAndDataSets_View] ------------------------------'
  If Exists (select Name
           from sysobjects
            where Name = "RefiledItemAndDataSets_View" and type = "V")
  Drop View RefiledItemAndDataSets_View

  Print '-- [delete function: Items_tbl_DeleteDataRow_By_ID] ----------------------------'
  If Exists (select Name
             from sysobjects
             where Name = "items_tbl_DeleteDataRow_By_ID" and type = "P")
  Drop Procedure items_tbl_DeleteDataRow_By_ID

  Print '-- [delete function: ItemTblItemsToListView] -----------------------------------'
  If Exists (select Name
             from sysobjects
             where Name = "ItemTblItemsToListView" and type = "P")
  Drop Procedure ItemTblItemsToListView


  Print '-- [delete function: ItemsRefileResultsAddDataSet] -----------------------------'
  If Exists (select Name
             from sysobjects
             where Name = "ItemsRefileResultsAddDataSet" and type = "P")
  Drop Procedure ItemsRefileResultsAddDataSet


  Print '-- [delete function: ItemsRev_RefileProcessState_Set] --------------------------'
  If Exists (select Name
             from sysobjects
             where Name = "ItemsRev_RefileProcessState_Set" and type = "P")
  Drop Procedure ItemsRev_RefileProcessState_Set

  Print '-- [delete function: ItemsRefileResults_GetId] ---------------------------------'
  If Exists (select Name
             from sysobjects
             where Name = "ItemsRefileResults_GetId" and type = "P")
  Drop Procedure ItemsRefileResults_GetId

  --  delete Items_tbl 11.01.2011
  if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Items_tbl]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  BEGIN
   Print '-- [delete: Table:Items_tbl] -----------------------------------------'
   DROP TABLE [dbo].[Items_tbl]
  END


  --  delete ItemsRefileResults_tbl 11.01.2011
  if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ItemsRefileResults_tbl]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  BEGIN
   Print '-- [delete: Table:ItemsRefileResults_tbl] ---------------------------------'
   DROP TABLE [dbo].[ItemsRefileResults_tbl]
  END

  EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
  print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end


 -- rem wichtig @Name muss eindeutig sein
 -- ItemsTbl CleanUp Aktion erstellt 11.01.2011 12:04 J.Fes
 set @Name='Objects_tbl_DeleteDataRow_By_ID-Remove'
 set @ValueCurr=''
 set @ValueDesired='2011-03-04-01'
 EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
 if @ValueCompareStat <> 1
 begin
  Print '-- [Objects_tbl_DeleteDataRow_By_ID] ------------------------------------'
  If Exists (select Name
             from sysobjects
             where Name = "Objects_tbl_DeleteDataRow_By_ID" and type = "P")
             Drop Procedure Objects_tbl_DeleteDataRow_By_ID

  EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
  print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end


set @Name='Sites_tbl_Update_OracleTblNameInfodbaReplace'
set @ValueCurr=''
set @ValueDesired='2011-03-07-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   set @ExecuteSQLstr='UPDATE Sites_tbl set OracleTblNameInfodbaReplace=' + ''''  + '''' + ' where OracleTblNameInfodbaReplace is null'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   execute sp_executesql @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end

set @Name='Sites_tbl_Update_Tns_Admin_Add_TnsNames.Ora'
set @ValueCurr=''
set @ValueDesired='2011-10-30-02'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   set @ExecuteSQLstr='UPDATE dbo.Sites_tbl set Tns_Admin=[Tns_Admin] + ' + '''' + '\tnsnames.ora'  + ''''  +
                      ' WHERE' +
                       ' dbo.Sites_tbl.Tns_Admin <> ' + '''' + '''' + ' AND' +
                       ' dbo.Sites_tbl.Tns_Admin NOT LIKE ' + '''' + '%\%.ora' + '''' + ' AND' +
                       ' dbo.Sites_tbl.Tns_Admin IS NOT NULL'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   execute sp_executesql @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end


set @Name='JobControlRules_tbl_Update_SelObjectsBy_FsHitCount_YN'
set @ValueCurr=''
set @ValueDesired='2011-10-31-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   set @ExecuteSQLstr='UPDATE JobControlRules_tbl set SelObjectsBy_FsHitCount_YN=0 where SelObjectsBy_FsHitCount_YN is null'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   execute sp_executesql @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end


set @Name='JobControlRules_tbl_Update_JobResourcePoints'
set @ValueCurr=''
set @ValueDesired='2011-10-31-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   set @ExecuteSQLstr='UPDATE JobControlRules_tbl set JobResourcePoints=0 where JobResourcePoints is null'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   execute sp_executesql @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end

set @Name='JobControlRules_tbl_Update_JobResult_ProcStateValueRule'
set @ValueCurr=''
set @ValueDesired='2011-10-31-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   set @ExecuteSQLstr='UPDATE JobControlRules_tbl set [JobResult_ProcStateValueRule]=' + '''' + '''' + ' where [JobResult_ProcStateValueRule] is null'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   execute sp_executesql @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end

-- entnommen 18.07.2014/J.Fes
-- set @Name='ImportTcApBomLineUgGometryNo_DoCount'
-- set @ValueCurr=''
-- set @ValueDesired='2011-08-11-01'
-- EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
-- if @ValueCompareStat <> 1
--  begin
--    print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
--    print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
--    set @ExecuteSQLstr='UPDATE Sites_tbl set ImportTcApBomLineUgGometryNo_DoCount=1 where ImportTcApBomLineUgGometryNo_DoCount is null'
--    execute sp_executesql @ExecuteSQLstr
--    print @Name + ' [Update 1/1:->DONE!] ' + @ExecuteSQLstr
--    EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
--    print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
--  end


-- Reset ObjectType for Dataset from Objects_tbl where ObjectClass = "IR"
set @Name='Objects_tbl_Update_IRS_ObjectType_RESET'
set @ValueCurr=''
set @ValueDesired='2012-02-03-02'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   set @ExecuteSQLstr='UPDATE Objects_tbl set ObjectType=' + '''~''' + ' where ObjectClass=''IR'' and ObjectType in (''~'',''UGMASTER'',''UGPART'',''UGALTREP'',''UGMANIFESTATION'',''UGSCENARIO'',''NXSIMULATION'',''CAEGEOM'',''CAEMESH'',''CAESOLUTION'')'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   execute sp_executesql @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end

-- #New: 13.10.2012 J.Fes
set @Name='JobControlRules_tbl_Update_JobPacket_ContainOnlyObjOfDiffrentI'
set @ValueCurr=''
set @ValueDesired='2012-10-13-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   set @ExecuteSQLstr='UPDATE JobControlRules_tbl set [JobPacket_ContainOnlyObjOfDiffrentI]=0 where [JobPacket_ContainOnlyObjOfDiffrentI] is null'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   execute sp_executesql @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end


-- #New: 13.10.2012 J.Fes
-- set @Name='JobControlRules_tbl_Update_JobPacket_ContainOnlyObjOfDiffrentIR'
-- set @ValueCurr=''
-- set @ValueDesired='2012-10-13-02'
-- EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
-- if @ValueCompareStat <> 1
--  begin
--    print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
--    set @ExecuteSQLstr='UPDATE JobControlRules_tbl set [JobPacket_ContainOnlyObjOfDiffrentIR]=0 where [JobPacket_ContainOnlyObjOfDiffrentIR] is null'
--    print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
--    execute sp_executesql @ExecuteSQLstr
--    EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
--    print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
--  end


-- #New: 13.10.2012 J.Fes
set @Name='JobControlRules_tbl_Update_JobPacket_JobSumObjectCount'
set @ValueCurr=''
set @ValueDesired='2011-10-31-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   set @ExecuteSQLstr='UPDATE JobControlRules_tbl set JobPacket_JobSumObjectCount=0 where JobPacket_JobSumObjectCount is null'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   execute sp_executesql @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end

-- #New: 13.10.2012 J.Fes
set @Name='JobControlRules_tbl_Update_SelObjectsBy_Status'
set @ValueCurr=''
set @ValueDesired='2011-10-31-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   set @ExecuteSQLstr='UPDATE JobControlRules_tbl set [SelObjectsBy_Status]=' + '''' + '''' + ' where [SelObjectsBy_Status] is null'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   execute sp_executesql @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end


-- #New: 27.03.2013 21:26 J.Fes
set @Name='ImportDataCleanup'
set @ValueCurr=''
set @ValueDesired='2013-03-27-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   set @ExecuteSQLstr='UPDATE Sites_tbl set ImportDataCleanup=1 where ImportDataCleanup is null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 1/1:->DONE!] ' + @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end

-- #New: 27.03.2013 21:26 J.Fes
set @Name='TCArchitecture'
set @ValueCurr=''
set @ValueDesired='2013-03-29-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   set @ExecuteSQLstr='UPDATE Sites_tbl set TCArchitecture=' + '''' + 'TCUA' + '''' + ' where TCArchitecture is null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 1/1:->DONE!] ' + @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end




set @Name='ImportPrjData'
set @ValueCurr=''
set @ValueDesired='2013-04-02-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   set @ExecuteSQLstr='UPDATE Sites_tbl set ImportPrjData=0 where ImportPrjData is null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 1/1:->DONE!] ' + @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end


-- #New: 27.03.2013 21:26 J.Fes
set @Name='SelObjectsBy_ObjectSpecSelRule'
set @ValueCurr=''
set @ValueDesired='2013-07-19-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   set @ExecuteSQLstr='UPDATE JobControlRules_tbl set [SelObjectsBy_ObjectSpecSelRule]=' + '''DS_of_IR'''
   set @ExecuteSQLstr=@ExecuteSQLstr + ' where [ProcStateCol] = ' + '''' + 'ProcStateColRf'  + ''''
   set @ExecuteSQLstr=@ExecuteSQLstr + '       and [SelObjectsBy_ObjectSpecSelRule] is null'
   print @Name + ' [Update 1/2:->Do Update!] ' + @ExecuteSQLstr
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 1/2:->Done!] '

   set @ExecuteSQLstr='UPDATE JobControlRules_tbl set [SelObjectsBy_ObjectSpecSelRule]=' + '''NotInUse'''
   set @ExecuteSQLstr=@ExecuteSQLstr + ' where [SelObjectsBy_ObjectSpecSelRule] is null'
   print @Name + ' [Update 2/2:->Do Update!] ' + @ExecuteSQLstr
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 2/2:->Done!] '

   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired

 end

set @Name='ImportItemDataAll'
set @ValueCurr=''
set @ValueDesired='2013-08-16-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   set @ExecuteSQLstr='UPDATE Sites_tbl set ImportItemDataAll=0 where ImportItemDataAll is null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 1/1:->DONE!] ' + @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end

set @Name='ImportMultiSiteData'
set @ValueCurr=''
set @ValueDesired='2013-08-21-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   set @ExecuteSQLstr='UPDATE Sites_tbl set ImportMultiSiteData=1 where ImportMultiSiteData is null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 1/1:->DONE!] ' + @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end


set @Name='ImportFs_Properties'
set @ValueCurr=''
set @ValueDesired='2013-08-26-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   set @ExecuteSQLstr='UPDATE Sites_tbl set ImportFs_Properties=0 where ImportFs_Properties is null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 1/1:->DONE!] ' + @ExecuteSQLstr
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end


set @Name='PLMPerfTblsRemove'
set @ValueCurr=''
set @ValueDesired='2014-08-06-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   Print 'Delete PLMPerf Tabels #New 06.08.2014 11:00 #Info now we use a seperated Database'
   if (object_id('tblStartzeiten') is not null)  Drop table tblStartzeiten
   if (object_id('tblChartTypes') is not null)  Drop table tblChartTypes
   if (object_id('tblComputer') is not null)  Drop table tblComputer
   if (object_id('tblComputerDetails') is not null)  Drop table tblComputerDetails
   if (object_id('tblEvents') is not null)  Drop table tblEvents
   if (object_id('tblFilter') is not null)  Drop table tblFilter
   if (object_id('tblImports') is not null)  Drop table tblImports
   if (object_id('tblImportTypes') is not null)  Drop table tblImportTypes
   if (object_id('tblLineStyles') is not null)  Drop table tblLineStyles
   if (object_id('tblMesslinien') is not null)  Drop table tblMesslinien
   if (object_id('tblMessungen') is not null)  Drop table tblMessungen
   if (object_id('tblMesswerte') is not null)  Drop table tblMesswerte
   if (object_id('tblMesswerteConfig') is not null)  Drop table tblMesswerteConfig
   if (object_id('tblPerfMess') is not null)  Drop table tblPerfMess
   if (object_id('tblPingMess') is not null)  Drop table tblPingMess
   if (object_id('tblUserCount') is not null)  Drop table tblUserCount
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end


set @Name='Objects_tbl_Update_add_ProcStateCol11..20'
set @ValueCurr=''
set @ValueDesired='2014-08-08-04'
set @UpdateDone=0
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'


   DECLARE @DoneCounter INT
   DECLARE @ToProcessN INT
   SET @ToProcessN = 0
   SET @DoneCounter = 0

   declare @Id  uniqueidentifier,
           @ObjectCliName nvarchar(255),
           @ObjectClass nvarchar(10),
           @DoAction bit,
           @PrintEvery int

   -- #ToDo: Setup: print del ervery n'times
   set @PrintEvery=1000
   -- #ToDo: Setup: @DoAction Action
   --  if @DoAction = 1 then Data is deleted
   --  if @DoAction = 0 then only Print is done
   set @DoAction=1

   select @ToProcessN=count(*)
     from dbo.Objects_tbl
     WHERE ProcStateCol20 is null

   -- Cursor to process all Objects
   declare tbl_Cursor cursor fast_forward for
   select Id, ObjectCliName, ObjectClass
     from dbo.Objects_tbl
     where ProcStateCol20 is null

   set nocount on
   open tbl_Cursor
    -- alle Objekte durchlaufen die durch den Cursor durchlaufen
    while 1=1
     begin
       SET @DoneCounter = @DoneCounter + 1
       fetch next from tbl_Cursor into @Id, @ObjectCliName, @ObjectClass
       -- Ausstieg wenn nichts zu löschen ist
       if (@ToProcessN =0)
       begin
         print('Result...........: No Data found to Update')
        if @DoAction = 1
        begin
          -- set UpdateDone true see actins below
          set @UpdateDone=1
         end
         break
       end
       -- exit if last element is processed
       if (@@fetch_status <> 0)
       begin
        if @DoAction = 1
        begin
          -- set UpdateDone true see actins below
          set @UpdateDone=1
        end
        break
       end

       -- #Debug: Austieg für test
       -- if (@DoneCounter >=2) break

       if (@DoneCounter = 1) or (@DoneCounter = @ToProcessN) or (@DoneCounter % @PrintEvery = 0)
       begin
          print('Update:[' + CONVERT(nvarchar(64),@DoneCounter) + '/' + CONVERT(nvarchar(64),@ToProcessN) + ':' + Str((100.00*@DoneCounter/@ToProcessN),6,2)  + '%]' +
                ' Obj:[' + @ObjectClass + ':' + @ObjectCliName + ']')
       end

       if @DoAction = 1
       begin
          -- Step: Do the Update
        	 UPDATE Objects_tbl
        	        set ProcStateCol11= 'N',
                 				ProcStateCol12= 'N',
                 				ProcStateCol13= 'N',
                 				ProcStateCol14= 'N',
                 				ProcStateCol15= 'N',
                 				ProcStateCol16= 'N',
                 				ProcStateCol17= 'N',
                 				ProcStateCol18= 'N',
                 				ProcStateCol19= 'N',
                 				ProcStateCol20= 'N'
        	  where Objects_tbl.Id = @Id
       end
     end
   close tbl_Cursor
   deallocate tbl_Cursor

   if @UpdateDone = 1
   begin
     -- set UpdateDone true see actins below
     EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
     print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
   end
   ELSE
   BEGIN
     print @Name + ' [Update:' + @ValueDesired + ' -> !! -- NOT DONE -- !!]'
   end
end


-- #New: 15.09.2014 J.Fes
set @Name='AddAdditional_Data'
set @ValueCurr=''
set @ValueDesired='2014-09-15-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'

   set @ExecuteSQLstr='UPDATE JobControlRules_tbl set [AddAdditional_Data]=' + '''NotInUse'''
   set @ExecuteSQLstr=@ExecuteSQLstr + ' where [AddAdditional_Data] is null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
 end



-- #New: 15.09.2014 J.Fes
set @Name='SelObjectsBy_SQLScript_YN'
set @ValueCurr=''
set @ValueDesired='2014-09-15-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'

   set @ExecuteSQLstr='UPDATE JobControlRules_tbl set SelObjectsBy_SQLScript_YN=0 where SelObjectsBy_SQLScript_YN is null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
 end

-- #New 03.06.2015 16:43
set @Name='IrAndBOMSettings'
set @ValueCurr=''
set @ValueDesired='2015-06-03-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   set @ExecuteSQLstr='UPDATE Sites_tbl set Config_IrRevLatestRule=''Rul1_LatestByCreationDate'' where Config_IrRevLatestRule is null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 1/2:->DONE!] ' + @ExecuteSQLstr

   set @ExecuteSQLstr='UPDATE Sites_tbl set Config_BOMPreciseRule=''Rul1_UsePreciseYes'' where Config_BOMPreciseRule is null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 2/2:->DONE!] ' + @ExecuteSQLstr


   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end


set @Name='Item_IrLatestRank_UpdateAll'
set @ValueCurr=''
set @ValueDesired='2015-06-03-03'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   set @ExecuteSQLstr='Item_IrLatestRank_UpdateAll'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 1/1:->DONE!] ' + @ExecuteSQLstr

   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end

set @Name='Objects_tbl_Update_add_ProcStateColMc'
set @ValueCurr=''
set @ValueDesired='2016-02-26-02'
set @UpdateDone=0
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'


   SET @ToProcessN = 0
   SET @DoneCounter = 0
   set @PrintEvery=1000
   set @DoAction=1
   select @ToProcessN=count(*)
     from dbo.Objects_tbl
     WHERE ProcStateColMc is null

   -- Cursor to process all Objects
   declare tbl_Cursor cursor fast_forward for
   select Id, ObjectCliName, ObjectClass
     from dbo.Objects_tbl
     where ProcStateColMc is null

   set nocount on
   open tbl_Cursor
    -- alle Objekte durchlaufen die durch den Cursor durchlaufen
    while 1=1
     begin
       SET @DoneCounter = @DoneCounter + 1
       fetch next from tbl_Cursor into @Id, @ObjectCliName, @ObjectClass
       -- Ausstieg wenn nichts zu löschen ist
       if (@ToProcessN =0)
       begin
         print('Result...........: No Data found to Update')
        if @DoAction = 1
        begin
          -- set UpdateDone true see actins below
          set @UpdateDone=1
         end
         break
       end
       -- exit if last element is processed
       if (@@fetch_status <> 0)
       begin
        if @DoAction = 1
        begin
          -- set UpdateDone true see actins below
          set @UpdateDone=1
        end
        break
       end

       if (@DoneCounter = 1) or (@DoneCounter = @ToProcessN) or (@DoneCounter % @PrintEvery = 0)
       begin
          print('Update:[' + CONVERT(nvarchar(64),@DoneCounter) + '/' + CONVERT(nvarchar(64),@ToProcessN) + ':' + Str((100.00*@DoneCounter/@ToProcessN),6,2)  + '%]' +
                ' Obj:[' + @ObjectClass + ':' + @ObjectCliName + ']')
       end

       if @DoAction = 1
       begin
          -- Step: Do the Update
        	 UPDATE Objects_tbl
        	        set ProcStateColMc= 'N'
        	  where Objects_tbl.Id = @Id
       end
     end
   close tbl_Cursor
   deallocate tbl_Cursor

   if @UpdateDone = 1
   begin
     -- set UpdateDone true see actins below
     EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
     print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
   end
   ELSE
   BEGIN
     print @Name + ' [Update:' + @ValueDesired + ' -> !! -- NOT DONE -- !!]'
   end
end


set @Name='Objects_tbl X.TC.Struc to X.PLM Update'
set @ValueCurr=''
set @ValueDesired='2017-07-06-01'
set @UpdateDone=0
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'

   set @UpdateCounter = 0
   -- Step: Do the Update
   print '-- Update ProcStateCol01 -- values X.TC.Struc.ERR to: X.PLM.ERR'
 	 UPDATE Objects_tbl set Objects_tbl.ProcStateCol01 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol01 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol02 -- values X.TC.Struc.ERR to: X.PLM.ERR'
 	 UPDATE Objects_tbl set Objects_tbl.ProcStateCol02 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol02 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol03 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol03 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol03 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol04 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol04 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol04 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol05 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol05 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol05 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol06 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol06 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol06 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol07 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol07 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol07 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol08 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol08 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol08 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol09 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol09 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol09 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol10 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol10 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol10 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol11 -- values X.TC.Struc.ERR to: X.PLM.ERR'
 	 UPDATE Objects_tbl set Objects_tbl.ProcStateCol11 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol11 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol12 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol12 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol12 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol13 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol13 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol13 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol14 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol14 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol14 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol15 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol15 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol15 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol16 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol16 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol16 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol17 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol17 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol17 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol18 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol18 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol18 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol19 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol19 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol19 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateCol20 -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateCol20 = 'X.PLM.ERR' where Objects_tbl.ProcStateCol20 = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateColMc -- values X.TC.Struc.ERR to: X.PLM.ERR'
   UPDATE Objects_tbl set Objects_tbl.ProcStateColMc = 'X.PLM.ERR' where Objects_tbl.ProcStateColMc = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT

   print '-- Update ProcStateColRf -- values X.TC.Struc.ERR to: X.PLM.ERR'
 	 UPDATE Objects_tbl set Objects_tbl.ProcStateColRf = 'X.PLM.ERR' where Objects_tbl.ProcStateColRf = 'X.TC.Struc.ERR'
   set @UpdateCounter = @UpdateCounter + @@ROWCOUNT
   print @Name + ' [MSG Update: values from:X.TC.Struc.MSG to: X.PLM.ERR Done:' + convert(varchar(10),@UpdateCounter) + ' (n) times]'

    select @UpdateCounter=count(*)
         from dbo.Objects_tbl
     WHERE    ProcStateCol01 = 'X.TC.Struc.ERR'
           or ProcStateCol02 = 'X.TC.Struc.ERR'
           or ProcStateCol03 = 'X.TC.Struc.ERR'
           or ProcStateCol04 = 'X.TC.Struc.ERR'
           or ProcStateCol05 = 'X.TC.Struc.ERR'
           or ProcStateCol06 = 'X.TC.Struc.ERR'
           or ProcStateCol07 = 'X.TC.Struc.ERR'
           or ProcStateCol08 = 'X.TC.Struc.ERR'
           or ProcStateCol09 = 'X.TC.Struc.ERR'
           or ProcStateCol10 = 'X.TC.Struc.ERR'
           or ProcStateCol11 = 'X.TC.Struc.ERR'
           or ProcStateCol12 = 'X.TC.Struc.ERR'
           or ProcStateCol13 = 'X.TC.Struc.ERR'
           or ProcStateCol14 = 'X.TC.Struc.ERR'
           or ProcStateCol15 = 'X.TC.Struc.ERR'
           or ProcStateCol16 = 'X.TC.Struc.ERR'
           or ProcStateCol17 = 'X.TC.Struc.ERR'
           or ProcStateCol18 = 'X.TC.Struc.ERR'
           or ProcStateCol19 = 'X.TC.Struc.ERR'
           or ProcStateCol20 = 'X.TC.Struc.ERR'
           or ProcStateColMc = 'X.TC.Struc.ERR'
           or ProcStateColRf = 'X.TC.Struc.ERR'

    if @UpdateCounter <> 0
    BEGIN
     print @Name + ' [ERR Update: values from:X.TC.Struc.ERR to: X.PLM.ERR found:' + convert(varchar(10),@UpdateCounter) + ' (n) with value X.TC.Struc.ERR]'
    END
    ELSE
    BEGIN
     print @Name + ' [OK Update: values from:X.TC.Struc.ERR to: X.PLM.ERR]'
     set @UpdateDone = 1
    END

   if @UpdateDone = 1
   begin
     -- set UpdateDone true see actins below
     EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
     print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
   end
   ELSE
   BEGIN
     print @Name + ' [Update:' + @ValueDesired + ' -> !! -- NOT DONE -- !!]'
   end
end


-- 21.11.2017 16:44  TC / NativFileSys / SAP
set @Name='DataSourceType'
set @ValueCurr=''
set @ValueDesired='2017-11-21-01'
EXECUTE zzzzzDbMaintain_valueGet @Name , @ValueCurr Output , @ValueDesired , @ValueCompareStat Output
if @ValueCompareStat <> 1
 begin
   print '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
   print @Name + ' [Update:' + @ValueDesired + ' ->Start!]'
   set @ExecuteSQLstr='UPDATE Sites_tbl set DataSourceType=''NativFileSys'' where NativeRoot_DP <> '''''
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 1/1:->DONE!] ' + @ExecuteSQLstr

   set @ExecuteSQLstr='UPDATE Sites_tbl set DataSourceType=''SAP'' where SAPSystemSettings_xml is not Null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 1/1:->DONE!] ' + @ExecuteSQLstr

   set @ExecuteSQLstr='UPDATE Sites_tbl set DataSourceType=''TC'' where DataSourceType is Null'
   execute sp_executesql @ExecuteSQLstr
   print @Name + ' [Update 1/1:->DONE!] ' + @ExecuteSQLstr

   EXECUTE zzzzzDbMaintain_valueSave @Name , @ValueDesired
   print @Name + ' [Update:' + @ValueDesired + ' ->DONE!]'
 end


EndeExit:
 Print '.........................................................................'
 Print ('Maintain Database: #DB_N# !Done!')
 Print '-------------------------------------------------------------------------'
 Print ''
GO
