CREATE TABLE [D001-20-1].[DSAHIST_KSD_ABSENCE](
  [Municipality] [int] NULL,
  [CaseNumberID] [int] NULL,
  [ExemptionForLateApplicaton] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [ManuelEndCause] [varchar](3) COLLATE Norwegian_100_CI_AS NULL,
  [AbsenceUUID] [varchar](45) COLLATE Norwegian_100_CI_AS NULL,
  [ApplicationDate] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [FirstDayOfAbsence] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [LastDayOfAbsence] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [ExpectedLastDayOfAbsence] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [FitForDutyWithinEightWeeks] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [InformedSicknessTypeCode] [varchar](2) COLLATE Norwegian_100_CI_AS NULL,
  [LastDayOfAbsenceReason] [varchar](2) COLLATE Norwegian_100_CI_AS NULL,
  [ManualGrantEndDate] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [ManualGrantStartDate] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [ManualRejectionReason] [varchar](3) COLLATE Norwegian_100_CI_AS NULL,
  [MarkForOutlay] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [MarkForAccident] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [MarkForWorkRelatedInjury] [varchar](2) COLLATE Norwegian_100_CI_AS NULL,
  [TransactionID] [varchar](45) COLLATE Norwegian_100_CI_AS NULL,
  [WorkRelatedInjuryApplicationDate] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [WorkRelatedInjuryReportedTo] [varchar](200) COLLATE Norwegian_100_CI_AS NULL,
  [CompanyEmail] [varchar](100) COLLATE Norwegian_100_CI_AS NULL,
  [CompanyTelephone] [varchar](20) COLLATE Norwegian_100_CI_AS NULL,
  [InquirerID] [varchar](60) COLLATE Norwegian_100_CI_AS NULL,
  [ManualGrantCause] [varchar](2) COLLATE Norwegian_100_CI_AS NULL,
  [SigningDate] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [SigningTime] [varchar](6) 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],[CaseNumberID],[ExemptionForLateApplicaton],[ManuelEndCause],[AbsenceUUID],[ApplicationDate],[FirstDayOfAbsence],[LastDayOfAbsence],[ExpectedLastDayOfAbsence],[FitForDutyWithinEightWeeks],[InformedSicknessTypeCode],[LastDayOfAbsenceReason],[ManualGrantEndDate],[ManualGrantStartDate],[ManualRejectionReason],[MarkForOutlay],[MarkForAccident],[MarkForWorkRelatedInjury],[TransactionID],[WorkRelatedInjuryApplicationDate],[WorkRelatedInjuryReportedTo],[CompanyEmail],[CompanyTelephone],[InquirerID],[ManualGrantCause],[SigningDate],[SigningTime])),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_ABSENCE] On [D001-20-1].[DSAHIST_KSD_ABSENCE] (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 fraværet i forbindelse med en sygdom', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_ABSENCE';
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_ABSENCE', 
@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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'CaseNumberID';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'ExemptionForLateApplicaton';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'ManuelEndCause';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'AbsenceUUID';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'ApplicationDate';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'FirstDayOfAbsence';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'LastDayOfAbsence';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'ExpectedLastDayOfAbsence';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'FitForDutyWithinEightWeeks';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'InformedSicknessTypeCode';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'LastDayOfAbsenceReason';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'ManualGrantEndDate';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'ManualGrantStartDate';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'ManualRejectionReason';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'MarkForOutlay';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'MarkForAccident';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'MarkForWorkRelatedInjury';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'TransactionID';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'WorkRelatedInjuryApplicationDate';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'WorkRelatedInjuryReportedTo';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'CompanyEmail';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'CompanyTelephone';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'InquirerID';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'ManualGrantCause';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'SigningDate';
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_ABSENCE', 
@level2type = N'COLUMN', @level2name = N'SigningTime';
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_ABSENCE', 
@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_ABSENCE', 
@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_ABSENCE', 
@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_ABSENCE', 
@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_ABSENCE', 
@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_ABSENCE', 
@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_ABSENCE', 
@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_ABSENCE', 
@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_ABSENCE', 
@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_ABSENCE', 
@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_ABSENCE';
GO

