当前位置: 代码迷 >> Sql Server >> update能操作两个表吗。该怎么处理
  详细解决方案

update能操作两个表吗。该怎么处理

热度:15   发布时间:2016-04-27 20:45:31.0
update能操作两个表吗。
我有两个表,一个总表一个明细。
每一种产品在这两个表中都有一条记录
我如何让一个表的一个字段等另一个表的一个字段
怎么写update语句

谢谢。

------解决方案--------------------
用事物控制啊
------解决方案--------------------
看吧
ALTER PROCEDURE sp_UpdatePolicyInfo
(
@HolderName nvarchar(255),
@HolderBirthday datetime,
@HolderDocumentType int,
@HolderDocument nvarchar(50),
@HolderEmail nvarchar(50),
@HolderGender int,
@HolderMarriage int,
@HolderIndustry int,
@HolderOccupation int,
@HolderAge nvarchar(10),
@HolderMobile nvarchar(50),
@HolderCompanyName nvarchar(255),
@HolderCompanyAddress nvarchar(255),
@HolderCompanyZip nvarchar(10),
@HolderCompanyPhone nvarchar(50),
@HolderFamilyAddress nvarchar(255),
@HolderFamilyZip nvarchar(10),
@HolderFamilyPhone nvarchar(50),
@HolderCollectionAddress nvarchar(255),
@HolderCollectionZip nvarchar(10),
@HolderCollectionPhone nvarchar(50),
@HolderContactAddress nvarchar(255),
@HolderContactZip nvarchar(10),
@HolderContactPhone nvarchar(50),
@HolderOperator int,
@HolderModifyTime datetime,
@HolderF_Relationship int, --投保人信息 27

@InsuredName nvarchar(255),
@InsuredBirthday datetime,
@InsuredDocumentType int ,
@InsuredDocument nvarchar(50),
@InsuredEmail nvarchar(50),
@InsuredGender int,
@InsuredMarriage int,
@InsuredIndustry int,
@InsuredOccupation int,
@InsuredAge nvarchar(10),
@InsuredMobile nvarchar(50),
@InsuredCompanyName nvarchar(255),
@InsuredCompanyAddress nvarchar(255),
@InsuredCompanyZip nvarchar(10),
@InsuredCompanyPhone nvarchar(50),
@InsuredFamilyAddress nvarchar(255),
@InsuredFamilyZip nvarchar(10),
@InsuredFamilyPhone nvarchar(50),
@InsuredCollectionAddress nvarchar(255),
@InsuredCollectionZip nvarchar(10),
@InsuredCollectionPhone nvarchar(50),
@InsuredContactAddress nvarchar(255),
@InsuredContactZip nvarchar(10),
@InsuredContactPhone nvarchar(50),
@InsuredOperator int,
@InsuredModifyTime datetime, --被保人信息 29

@BeneficiaryName nvarchar(255),
@BeneficiaryBirthday datetime,
@BeneficiaryDocumentType int,
@BeneficiaryDocument nvarchar(255),
@BeneficiaryGender int,
@BeneficiaryRelationship int,
@BeneficiaryOperator int,
@BeneficiaryModifyTime datetime, --手艺人信息 8

@PolicyKey int,
@PolicyPremiumKey decimal,
@PolicyAFYP decimal,
@PolicyInitalPaymentMode int ,
@PolicyRenewalPaymentMode int,
@PolicyProductKey int ,
@PolicyBankKey int,
@PolicyAccount nvarchar(50),
@PolicyCheckPerson int,
@PolicyOperator int,
@PolicyModifyTime datetime,
@PolicyDescription nvarchar(255) --保单信息
)
AS
BEGIN TRANSACTION
declare @HolderKey int ,@InsuredKey int ,@BeneficiaryKey int
declare @error1 int,@error2 int ,@error3 int,@error4 int

select @HolderKey=HolderKey,@InsuredKey=InsuredKey,@BeneficiaryKey=BeneficiaryKey from TR_P_Policy where [email protected]

UPDATE TR_P_Holder
SET [Name] [email protected], Birthday [email protected], DocumentType [email protected], Document [email protected], Email [email protected],
Gender [email protected], Marriage [email protected], Industry [email protected], Occupation [email protected], Age [email protected], Mobile [email protected],
CompanyName [email protected],CompanyAddress [email protected], CompanyZip [email protected], CompanyPhone [email protected],
FamilyAddress [email protected], FamilyZip [email protected], FamilyPhone [email protected], CollectionAddress [email protected],
  相关解决方案