日期:2014-05-17  浏览次数:20780 次

如何动态改变这条试图中的某个值


/*
社保每人每月缴款总额
*/
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)


这是一条查询某员工一个月内所需要缴纳的社保金额

但是a.BasePay 是通过其他的2个表来动态获取的

怎么加进去呢  作为条件
那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