104 lines
6.5 KiB
MySQL
104 lines
6.5 KiB
MySQL
|
|
|||
|
CREATE TABLE [dbo].[JDGL_LowTankCompletion](
|
|||
|
[LowTankCompletionId] [nvarchar](50) NOT NULL,
|
|||
|
[ProjectId] [nvarchar](50) NULL,
|
|||
|
[Code] [nvarchar](50) NULL,
|
|||
|
[Name] [nvarchar](50) NULL,
|
|||
|
[Unit] [nvarchar](50) NULL,
|
|||
|
[TotalNum] [decimal](18, 2) NULL,
|
|||
|
[PlanNum] [decimal](18, 2) NULL,
|
|||
|
[RealNum] [decimal](18, 2) NULL,
|
|||
|
[StartDate] [datetime] NULL,
|
|||
|
[EndDate] [datetime] NULL,
|
|||
|
[CompileMan] [nvarchar](50) NULL,
|
|||
|
[CompileDate] [datetime] NULL,
|
|||
|
CONSTRAINT [PK_JDGL_LowTankCompletion] PRIMARY KEY CLUSTERED
|
|||
|
(
|
|||
|
[LowTankCompletionId] ASC
|
|||
|
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
|||
|
) ON [PRIMARY]
|
|||
|
|
|||
|
GO
|
|||
|
|
|||
|
ALTER TABLE [dbo].[JDGL_LowTankCompletion] WITH CHECK ADD CONSTRAINT [FK_JDGL_LowTankCompletion_Base_Project] FOREIGN KEY([ProjectId])
|
|||
|
REFERENCES [dbo].[Base_Project] ([ProjectId])
|
|||
|
GO
|
|||
|
|
|||
|
ALTER TABLE [dbo].[JDGL_LowTankCompletion] CHECK CONSTRAINT [FK_JDGL_LowTankCompletion_Base_Project]
|
|||
|
GO
|
|||
|
|
|||
|
ALTER TABLE [dbo].[JDGL_LowTankCompletion] WITH CHECK ADD CONSTRAINT [FK_JDGL_LowTankCompletion_Sys_User] FOREIGN KEY([CompileMan])
|
|||
|
REFERENCES [dbo].[Sys_User] ([UserId])
|
|||
|
GO
|
|||
|
|
|||
|
ALTER TABLE [dbo].[JDGL_LowTankCompletion] CHECK CONSTRAINT [FK_JDGL_LowTankCompletion_Sys_User]
|
|||
|
GO
|
|||
|
|
|||
|
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'<EFBFBD><EFBFBD><EFBFBD><EFBFBD>' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JDGL_LowTankCompletion', @level2type=N'COLUMN',@level2name=N'LowTankCompletionId'
|
|||
|
GO
|
|||
|
|
|||
|
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'<EFBFBD><EFBFBD>ĿId' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JDGL_LowTankCompletion', @level2type=N'COLUMN',@level2name=N'ProjectId'
|
|||
|
GO
|
|||
|
|
|||
|
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'<EFBFBD><EFBFBD><EFBFBD>ޱ<EFBFBD><EFBFBD><EFBFBD>' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JDGL_LowTankCompletion', @level2type=N'COLUMN',@level2name=N'Code'
|
|||
|
GO
|
|||
|
|
|||
|
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'<EFBFBD><EFBFBD><EFBFBD><EFBFBD>' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JDGL_LowTankCompletion', @level2type=N'COLUMN',@level2name=N'Name'
|
|||
|
GO
|
|||
|
|
|||
|
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'<EFBFBD><EFBFBD>λ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JDGL_LowTankCompletion', @level2type=N'COLUMN',@level2name=N'Unit'
|
|||
|
GO
|
|||
|
|
|||
|
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JDGL_LowTankCompletion', @level2type=N'COLUMN',@level2name=N'TotalNum'
|
|||
|
GO
|
|||
|
|
|||
|
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'<EFBFBD><EFBFBD><EFBFBD>ڼƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JDGL_LowTankCompletion', @level2type=N'COLUMN',@level2name=N'PlanNum'
|
|||
|
GO
|
|||
|
|
|||
|
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JDGL_LowTankCompletion', @level2type=N'COLUMN',@level2name=N'RealNum'
|
|||
|
GO
|
|||
|
|
|||
|
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JDGL_LowTankCompletion', @level2type=N'COLUMN',@level2name=N'StartDate'
|
|||
|
GO
|
|||
|
|
|||
|
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JDGL_LowTankCompletion', @level2type=N'COLUMN',@level2name=N'EndDate'
|
|||
|
GO
|
|||
|
|
|||
|
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JDGL_LowTankCompletion', @level2type=N'COLUMN',@level2name=N'CompileMan'
|
|||
|
GO
|
|||
|
|
|||
|
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JDGL_LowTankCompletion', @level2type=N'COLUMN',@level2name=N'CompileDate'
|
|||
|
GO
|
|||
|
|
|||
|
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'<EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JDGL_LowTankCompletion'
|
|||
|
GO
|
|||
|
|
|||
|
|
|||
|
|
|||
|
CREATE VIEW [dbo].[View_JDGL_LowTankCompletion]
|
|||
|
AS
|
|||
|
select distinct ql.*,
|
|||
|
CONVERT(FLOAT,(select sum(ISNULL(PlanNum,0)) from JDGL_LowTankCompletion where ProjectId=ql.ProjectId and Code=ql.Code and Name=ql.Name and Unit=ql.Unit and EndDate<=getdate())) as TotalPlanNum,
|
|||
|
CONVERT(FLOAT,(select sum(ISNULL(RealNum,0)) from JDGL_LowTankCompletion where ProjectId=ql.ProjectId and Code=ql.Code and Name=ql.Name and Unit=ql.Unit and EndDate<=getdate())) as TotalRealNum,
|
|||
|
CONVERT(NVARCHAR(10),((CAST(CASE ISNULL(ql.PlanNum,0) WHEN 0 THEN 0
|
|||
|
ELSE 100*ISNULL(ql.RealNum,0) / (1.0 *ql.PlanNum) END AS DECIMAL(9,2)))))+'%'
|
|||
|
AS Rate,
|
|||
|
CONVERT(NVARCHAR(10),((CAST(CASE (select sum(ISNULL(PlanNum,0)) from JDGL_LowTankCompletion where ProjectId=ql.ProjectId and Code=ql.Code and Name=ql.Name and Unit=ql.Unit and EndDate<=getdate()) WHEN 0 THEN 0
|
|||
|
ELSE 100*(select sum(ISNULL(RealNum,0)) from JDGL_LowTankCompletion where ProjectId=ql.ProjectId and Code=ql.Code and Name=ql.Name and Unit=ql.Unit and EndDate<=getdate()) / (1.0 *(select sum(ISNULL(PlanNum,0)) from JDGL_LowTankCompletion where ProjectId=ql.ProjectId and Code=ql.Code and Name=ql.Name and Unit=ql.Unit and EndDate<=getdate())) END AS DECIMAL(9,2)))))+'%'
|
|||
|
AS TotalRate,
|
|||
|
CONVERT(NVARCHAR(10),((CAST(CASE ISNULL(ql.TotalNum,0) WHEN 0 THEN 0
|
|||
|
ELSE 100*(select sum(ISNULL(RealNum,0)) from JDGL_LowTankCompletion where ProjectId=ql.ProjectId and Code=ql.Code and Name=ql.Name and Unit=ql.Unit and EndDate<=getdate()) / (1.0 *ql.TotalNum) END AS DECIMAL(9,2)))))+'%'
|
|||
|
AS SumRate,
|
|||
|
CONVERT(FLOAT,(select sum(ISNULL(PlanNum,0)) from JDGL_LowTankCompletion where ProjectId=ql.ProjectId and Code=ql.Code and Name=ql.Name and Unit=ql.Unit and EndDate<getdate())) as LastTotalPlanNum,
|
|||
|
CONVERT(FLOAT,(select sum(ISNULL(RealNum,0)) from JDGL_LowTankCompletion where ProjectId=ql.ProjectId and Code=ql.Code and Name=ql.Name and Unit=ql.Unit and EndDate<getdate())) as LastTotalRealNum
|
|||
|
from [dbo].JDGL_LowTankCompletion ql
|
|||
|
where ql.LowTankCompletionId=(select top 1 LowTankCompletionId from [JDGL_LowTankCompletion] q where ProjectId=ql.ProjectId and Code=ql.Code and q.Name=ql.Name and q.Unit=ql.Unit and q.ProjectId=ql.ProjectId order by q.EndDate desc)
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
GO
|
|||
|
|
|||
|
|