Print ''
Print '-------------------------------------------------------------------------'
Print ' using Database: #DB_N#'
Print ' Table         : [JobControlActivStatusRules_tbl]'
Print ' Creation Date : 23.02.2021'
Print ' Autor         : S.Gueth'
Print '-------------------------------------------------------------------------'

use [#DB_N#]

Declare @MyActionMsg1 nvarchar (max)
Declare @MyTableName nvarchar (max)
    set @MyTableName='JobControlActivStatusRules_tbl'

--------------------------------------------------------------------------------
-- verzweigen auf TableCreate: oder TableUpdate:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[JobControlActivStatusRules_tbl]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  BEGIN
   goto TableUpdate
  END
ELSE
  BEGIN
   goto TableCreate
  END
  


--------------------------------------------------------------------------------
TableCreate:
  set @MyActionMsg1=
      '-- Table: [JobControlActivStatusRules_tbl] dose not exist and will be created new'
  Print (@MyActionMsg1)

  -- Info: bei Struktur anpassungen GitterVar_Cls.ReplaceTextString beachten
  CREATE TABLE [dbo].[JobControlActivStatusRules_tbl] (
         [Id]                             [uniqueidentifier] NOT NULL DEFAULT NEWSEQUENTIALID(),
         [JobControlActivStatusRule_xml]  [xml] NULL
  ) ON [PRIMARY]

  goto CheckCreateIndex


--------------------------------------------------------------------------------
TableUpdate:

  set @MyActionMsg1=
       '-- Table: [JobControlActivStatusRules_tbl] exist and will be updated'
  Print (@MyActionMsg1)

  Declare @ColumeName nvarchar (256)
  Declare @ColumeNameOld nvarchar (256)
  Declare @ColumeNameNew nvarchar (256)
  Declare @ExecuteSQLstr nvarchar (max)
                         

  -- New 31.10.2018 S.Gueth
  --set @ColumeName='JobControlActivInfo'
  --if (Select Coalesce(Col_length(@MyTableName,@ColumeName),0)) = 0
  --  begin
  --    print ('Create Column: [' + @ColumeName + '] stores last JobControlActivStatus Rule information [(new 31.10.2018/S.Gueth)]')
  --    set @ExecuteSQLstr='ALTER TABLE [dbo].[' + @MyTableName + '] ADD [' + @ColumeName +'] [nvarchar] (max)'
  --    execute (@ExecuteSQLstr)
  --  end

goto CheckCreateIndex
--------------------------------------------------------------------------------
  CheckCreateIndex:

  EXECUTE JF_PrimKeyCheckCreateDef 'JobControlActivStatusRuleIdx_pk',   @MyTableName, 'Id'
  
--------------------------------------------------------------------------------
EndeExit:
 Print '------------------------------------------------------------------------'
 Print 'Done on Database: #DB_N#'
 Print '------------------------------------------------------------------------'

GO
