日期:2014-05-17 浏览次数:20846 次
/*
社保每人每月缴款总额
*/
CREATE VIEW dbo.v_ri_SocSumPay
AS
SELECT a.*, a.BasePay * b.Pay * 0.01 AS SumPay
FROM dbo.t_ri_SocialsecurityManagement a LEFT OUTER JOIN
(SELECT (SUM(PersonalPay) + SUM(CompanyPay)) AS Pay,
PaymentStandardId
FROM t_ri_PaymentStandardItem
GROUP BY PaymentStandardId) b ON
a.PaymentStandardId = b.PaymentStandardId
WHERE (a.State = 1) AND (a.Status = 2) AND (a.EffectiveDate IS NOT NULL) and EXISTS (select * from v_ri_SocialsecurityPayItem where SocialsecurityManagementId=a.SocialsecurityManagementId and Status = 2)
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[t_ri_BaseUpdateItem]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[t_ri_BaseUpdateItem]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[t_ri_SocialsecurityManagement]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[t_ri_SocialsecurityManagement]
GO
CREATE TABLE [dbo].[t_ri_BaseUpdateItem] (
[BaseUpdateItemId] [uniqueidentifier] NULL ,
[CreatedOn] [datetime] NULL ,
[CreatedBy] [uniqueidentifier] NULL ,
[ModifiedOn] [datetime] NULL ,
[ModifiedBy] [uniqueidentifier] NULL ,
[VersionNumber] [timestamp] NULL ,
[Name] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[SocialsecurityManagementId] [uniqueidentifier] NULL ,
[EmployeeId] [uniqueidentifier] NULL ,
[BaseUpdateId] [uniqueidentifier] NULL ,
[EffectiveDate] [datetime] NULL ,
[NewBasePay] [money] NULL ,
[BasePay] [money] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[t_ri_SocialsecurityManagement] (
[SocialsecurityManagementId] [uniqueidentifier] NULL ,
[CreatedOn] [datetime] NULL ,
[CreatedBy] [uniqueidentifier] NULL ,
[ModifiedOn] [datetime] NULL ,
[ModifiedBy] [uniqueidentifier] NULL ,
[VersionNumber] [timestamp] NULL ,
[Number] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[SocialsecurityNumber] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[TransactorOn] [datetime] NULL ,
[TransactorBy] [uniqueidentifier] NULL ,
[EffectiveDate] [datetime] NULL ,
[Status] [int] NULL ,
[Description] [ntext] COLLATE Chinese_PRC_CI_AS NULL ,
[PaymentStandardId] [uniqueidentifier] NULL ,
[Name] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS