CREATE TABLE [D001-20-1].[DSAHIST_KSD_DECISION](
  [Municipality] [int] NULL,
  [CaseNumber] [int] NULL,
  [DecisionDate] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [DecisionStatus] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [DecisionStatusText] [varchar](20) COLLATE Norwegian_100_CI_AS NULL,
  [Decision] [varchar](3) COLLATE Norwegian_100_CI_AS NULL,
  [RejectionCause] [varchar](3) COLLATE Norwegian_100_CI_AS NULL,
  [MaximumDurationOnFirstDayOfAbs] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [MaximumDurationDate] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [ApplicationNotTimelySubmitted] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [AdditionalInformationNeeded] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [AutomaticGrantCause] [varchar](2) COLLATE Norwegian_100_CI_AS NULL,
  [AutomaticGrantEndDate] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [AutomaticGrantStartDate] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [AutomaticEndCause] [varchar](2) COLLATE Norwegian_100_CI_AS NULL,
  [VacationBenefitsReceived] [varchar](100) COLLATE Norwegian_100_CI_AS NULL,
  [MissingInformationFromEIndkoms] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [JobCenterNotification] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [IncapacitatedEndDate] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [ExceptForAutomaticDecision] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [DateOfUC202RelevantChange] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [OnlyEligibleInEmployerPeriod] [varchar](2) COLLATE Norwegian_100_CI_AS NULL,
  [SYS_KommuneId] [int] NULL,
  [SYS_BatchDate] [datetime2](3) NULL,
  [SYS_RowID] [bigint] identity(1,1) NOT NULL,
  [SYS_ExtractDate] [datetime2](3) NULL,
  [SYS_SourceFileID] [varchar](80) COLLATE Norwegian_100_CI_AS NULL,
  [SYS_RettelserTidAngivelse] [datetime2](3) NULL,
  [SYS_VersionID] [bigint] NULL,
  [SYS_Checksum] AS (CONVERT([bigint],hashbytes('SHA2_256',concat([Municipality],[CaseNumber],[DecisionDate],[DecisionStatus],[DecisionStatusText],[Decision],[RejectionCause],[MaximumDurationOnFirstDayOfAbs],[MaximumDurationDate],[ApplicationNotTimelySubmitted],[AdditionalInformationNeeded],[AutomaticGrantCause],[AutomaticGrantEndDate],[AutomaticGrantStartDate],[AutomaticEndCause],[VacationBenefitsReceived],[MissingInformationFromEIndkoms],[JobCenterNotification],[IncapacitatedEndDate],[ExceptForAutomaticDecision],[DateOfUC202RelevantChange],[OnlyEligibleInEmployerPeriod])),0)) PERSISTED,
  [SYS_ExecutionId] [bigint] NULL,
  [SYS_DataDeliveryBatchId_Create] [bigint] NULL
) 
on sys_batch_date_sc(SYS_BatchDate)
GO

CREATE UNIQUE CLUSTERED INDEX [IDX_CL_D001-20-1_DSAHIST_KSD_DECISION] On [D001-20-1].[DSAHIST_KSD_DECISION] (SYS_BatchDate, SYS_KommuneId, SYS_RowID) with (data_compression = page, STATISTICS_INCREMENTAL = ON) on sys_batch_date_sc(SYS_BatchDate);
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Indeholder oplysninger om alle de styrings- og beregningsinformationer som benyttes i forbindelse med afgørelsen.', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'Municipality';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'CaseNumber';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'DecisionDate';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'DecisionStatus';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'DecisionStatusText';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'Decision';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'RejectionCause';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'MaximumDurationOnFirstDayOfAbs';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'MaximumDurationDate';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'ApplicationNotTimelySubmitted';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'AdditionalInformationNeeded';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'AutomaticGrantCause';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'AutomaticGrantEndDate';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'AutomaticGrantStartDate';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'AutomaticEndCause';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'VacationBenefitsReceived';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'MissingInformationFromEIndkoms';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'JobCenterNotification';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'IncapacitatedEndDate';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'ExceptForAutomaticDecision';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'DateOfUC202RelevantChange';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'OnlyEligibleInEmployerPeriod';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder nummeret på den kommune, som rækken tilhører', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'SYS_KommuneId';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder information om, hvilken batch rækken er indlæst i', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'SYS_BatchDate';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder et fortløbende nummer, så alle rækker i tabellen har et unikt nummer', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'SYS_RowID';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder det dato stempel, som kildefilen er markeret med', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'SYS_ExtractDate';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder ID for den primære snitflade, hvor data i rækken stammer fra', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'SYS_SourceFileID';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder den forretningsmæssige tidsangivelse for rækken. Denne bruges hvis data skal slettes med tidsangivelse', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'SYS_RettelserTidAngivelse';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder et versionsnummer for den pågældende række', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'SYS_VersionID';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder cheksum info', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'SYS_Checksum';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'SysExecutionId', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'SYS_ExecutionId';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'SysDataDeliveryBatchIdCreate', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION', 
@level2type = N'COLUMN', @level2name = N'SYS_DataDeliveryBatchId_Create';
GO

EXEC sys.sp_addextendedproperty 
@name = N'DataArea', 
@value = N'ksd', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_DECISION';
GO

