﻿CREATE TABLE [dbo].[TabProdSc] (
    [KeyAMIL]      NVARCHAR (250)  NOT NULL,
    [CodDiesGroup] NVARCHAR (50)   NOT NULL,
    [KeyAM]        NVARCHAR (250)  NOT NULL,
    [CodItem]      NVARCHAR (50)   NOT NULL,
    [RawMat]       NVARCHAR (50)   NOT NULL,
    [CodPlant]     NVARCHAR (50)   NOT NULL,
    [HoleNum]      INT             NOT NULL,
    [NumSMED]      INT             NOT NULL,
    [KgTeo]        DECIMAL (18, 6) NOT NULL,
    [KgLor]        DECIMAL (18, 6) NOT NULL,
    [Duration]     DECIMAL (18, 6) NOT NULL,
    [ProdTeo]      AS              (isnull([KgTeo],(0))/case isnull([Duration],(1)) when (0) then (1) else isnull([Duration],(1)) end),
    [ScTec]        AS              ((1)-[KgTeo]/case [KgLor] when (0) then (1) else [KgLor] end),
    CONSTRAINT [PK_TabProdSc] PRIMARY KEY CLUSTERED ([KeyAMIL] ASC, [CodDiesGroup] ASC)
);


GO
CREATE NONCLUSTERED INDEX [i_TabProdSc_KeyAM]
    ON [dbo].[TabProdSc]([KeyAM] ASC)
    INCLUDE([KgTeo]);


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'produttività teorica (kgTeorici / durata h)', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'TabProdSc', @level2type = N'COLUMN', @level2name = N'ProdTeo';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'scarto tecnico: 1 - (KgTeorici/ISNULL(KgLordi,1))', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'TabProdSc', @level2type = N'COLUMN', @level2name = N'ScTec';

