CREATE TABLE [D001-20-1].[DSAHIST_KSD_SICKNESS_CASE](
  [Municipality] [int] NULL,
  [Casenumber] [int] NULL,
  [UserFacingKey] [varchar](15) COLLATE Norwegian_100_CI_AS NULL,
  [CasenumberUUID] [varchar](45) COLLATE Norwegian_100_CI_AS NULL,
  [RelatedReimbursementcaseCase] [int] NULL,
  [RelatedPerson] [int] NULL,
  [RelatedCompany] [int] NULL,
  [KSDCaseStatus] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [KSDCaseStatusText] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [MarkForRelocatedCase] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [GrantEndReached] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [RightOfWithdrawalUsed] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [JobcenterAdviseDate] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [CaseStatusChangeDate] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [StatuschangePostponed] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [ValidForTestSample] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [ManualCreationReason] [varchar](3) COLLATE Norwegian_100_CI_AS NULL,
  [ManualCreationReasonText] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [Deletioncode] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [CaseSelectedForRecourse] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [CaseSubjectForComplain] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [CaseSubjectForComplainEndDate] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [CaseSubjectForComplainStartDat] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [CaseSubjectForControl] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [Classification] [varchar](60) COLLATE Norwegian_100_CI_AS NULL,
  [InsightRegisterPerformed] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [RecourseEndDate] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [RecourseStartDate] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [SubjectAccessRequested] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [LegalBasis] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [OIOCaseState] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [Title] [varchar](100) 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],[UserFacingKey],[CasenumberUUID],[RelatedReimbursementcaseCase],[RelatedPerson],[RelatedCompany],[KSDCaseStatus],[KSDCaseStatusText],[MarkForRelocatedCase],[GrantEndReached],[RightOfWithdrawalUsed],[JobcenterAdviseDate],[CaseStatusChangeDate],[StatuschangePostponed],[ValidForTestSample],[ManualCreationReason],[ManualCreationReasonText],[Deletioncode],[CaseSelectedForRecourse],[CaseSubjectForComplain],[CaseSubjectForComplainEndDate],[CaseSubjectForComplainStartDat],[CaseSubjectForControl],[Classification],[InsightRegisterPerformed],[RecourseEndDate],[RecourseStartDate],[SubjectAccessRequested],[LegalBasis],[OIOCaseState],[Title])),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_SICKNESS_CASE] On [D001-20-1].[DSAHIST_KSD_SICKNESS_CASE] (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, der er specifikke for sygdomstilfældet, f.eks. årsag til manuel oprettelse.', 
@level0type = N'SCHEMA', @level0name = N'D001-20-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KSD_SICKNESS_CASE';
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_SICKNESS_CASE', 
@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_SICKNESS_CASE', 
@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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'UserFacingKey';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'CasenumberUUID';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'RelatedReimbursementcaseCase';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'RelatedPerson';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'RelatedCompany';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'KSDCaseStatus';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'KSDCaseStatusText';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'MarkForRelocatedCase';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'GrantEndReached';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'RightOfWithdrawalUsed';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'JobcenterAdviseDate';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'CaseStatusChangeDate';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'StatuschangePostponed';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'ValidForTestSample';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'ManualCreationReason';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'ManualCreationReasonText';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'Deletioncode';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'CaseSelectedForRecourse';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'CaseSubjectForComplain';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'CaseSubjectForComplainEndDate';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'CaseSubjectForComplainStartDat';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'CaseSubjectForControl';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'Classification';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'InsightRegisterPerformed';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'RecourseEndDate';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'RecourseStartDate';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'SubjectAccessRequested';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'LegalBasis';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'OIOCaseState';
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_SICKNESS_CASE', 
@level2type = N'COLUMN', @level2name = N'Title';
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_SICKNESS_CASE', 
@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_SICKNESS_CASE', 
@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_SICKNESS_CASE', 
@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_SICKNESS_CASE', 
@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_SICKNESS_CASE', 
@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_SICKNESS_CASE', 
@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_SICKNESS_CASE', 
@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_SICKNESS_CASE', 
@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_SICKNESS_CASE', 
@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_SICKNESS_CASE', 
@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_SICKNESS_CASE';
GO

