Print ''                
Print '-------------------------------------------------------------------------'
Print ' using Database: #DB_N#'
Print ' Table         : [tblMesswerteConfig]'
Print ' Creation Date : 13.11.2012'
Print ' Autor         : S.Güth'
Print '-------------------------------------------------------------------------'

use [#DB_N#]

Declare @MyActionMsg1 nvarchar (max)
Declare @MyTableName nvarchar (max)
set @MyTableName='tblMesswerteConfig'
DECLARE @ExecuteSQLstr nvarchar(max)

declare @indexNrCur  int
declare @indexNrEnd  int
declare @indexNrStr       varchar(32)
declare @IndexName        varchar(max)
declare @ProcStateColName varchar(max)
set @indexNrEnd = 10


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

--------------------------------------------------------------------------------
TableCreate:
  set @MyActionMsg1=
      '-- Table: [tblMesswerteConfig] dose not exist and will be created new'

  Print (@MyActionMsg1)


  CREATE TABLE tblMesswerteConfig
  (
          [MesswertFeldname]          nvarchar(50) NOT NULL,
          [MesswertName]              nvarchar(50) NOT NULL,
          [MesswertAktiv]             int,
          [YRangeMin]                 int,
          [YRangeMax]                 int,
          [LineColor]                 nvarchar(20),
          [LineThickness]             int,
          [LineStyleID]               int,
          CONSTRAINT tblMesswerteConfig_PK PRIMARY KEY ([MesswertFeldname])
  )
  ON [PRIMARY]
  
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert01', 'Wert01', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert02', 'Wert02', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert03', 'Wert03', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert04', 'Wert04', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert05', 'Wert05', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert06', 'Wert06', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert07', 'Wert07', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert08', 'Wert08', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert09', 'Wert09', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert10', 'Wert10', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert11', 'Wert11', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert12', 'Wert12', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert13', 'Wert13', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert14', 'Wert14', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert15', 'Wert15', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert16', 'Wert16', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert17', 'Wert17', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert18', 'Wert18', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert19', 'Wert19', 0, 0, 0, '', 0, 0)
  INSERT INTO tblMesswerteConfig (MesswertFeldname, MesswertName, MesswertAktiv, YRangeMin, YRangeMax, LineColor, LineThickness, LineStyleID) VALUES ('Wert20', 'Wert20', 0, 0, 0, '', 0, 0)


  goto CheckCreateIndex

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

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

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


 --- set @ColumeName='ObjectPuid'
 --- if (Select Coalesce(Col_length(@MyTableName,@ColumeName),0)) = 0
 ---   begin
 ---     print ('Create Column:' + @ColumeName +  ' .. PUID of Object (new 2.1.2009 J.Fes)')
 ---     set @ExecuteStr='ALTER TABLE [dbo].[' + @MyTableName + '] ADD [' + @ColumeName +'] nvarchar(15) COLLATE Latin1_General_CS_AS NULL'
 ---     execute (@ExecuteStr)
 ---   end




goto CheckCreateIndex

--------------------------------------------------------------------------------
CheckCreateIndex:

  EXECUTE JF_PrimKeyCheckCreateDef 'tblMesswerteConfig_pk',               @MyTableName, 'MesswertFeldname'
  EXECUTE JF_IndexCheckCreateDef   'tblMesswerteConfig_IDX_LineStyleID',  @MyTableName, 'LineStyleID' 

--------------------------------------------------------------------------------
EndeExit:
 Print ('   |-> Done on Database: #DB_N#')
 Print '------------------------------------------------------------------------'

GO
