SqlServer;在存储过程里,用一天语句执行多表插入时:
UPDATE MM_MerchAcc M--消息 102,级别 15,状态 1,过程 mm_EditMerchAcc,第 47 行
--'M' 附近有语法错误。
SET TName =@sz_TName, RName = @sz_RName, RNo = @sz_RNo, MDesc = @sz_MDesc, MCC = @i_MCC, Addr1 = @sz_Addr1,
Addr2 = @sz_Addr2, PCode = @sz_PCode, City = @sz_City, Province = @sz_Province, Country = @sz_Country,
Email = @sz_Email, URL = @sz_URL, LogoURL = ISNULL(@sz_LogoURL, LogoURL), Fax = @sz_Fax, MRiskGrp = @i_MRiskGrp,
MType = @i_MType, BizSDate = @sz_BizSDate, Phone = @sz_Phone, MobilePhone = @sz_MobilePhone, CPerson = @sz_CPerson,
Status= @i_Status, LMDate = @sz_MDate, LMBy = @sz_MBy ,DCC=@zs_Dcc
from MM_Usr U
WHERE U.Status=M.Status AND MAID = @i_MAID
请教多表更新怎么写啊,存储过程
但是给另外的表字段进行更新时,例如
UPDATE [dbo].[MM_MerchAcc]
SET
MM_MerchAcc.DCC=@zs_Dcc,
MM_Usr.Status=@u_Status --这里提示--消息 4104,级别 16,状态 1,过程 mm_EditMerchAcc,第 47 行
--无法绑定由多个部分组成的标识符 "MM_Usr.Status"。
from MM_Usr
WHERE MM_Usr.MAID = @i_MAID and MM_Usr.Status=MM_MerchAcc.Status
update M set ... from MM_MerchAcc M, MM_Usr U
MM_MerchAcc后面的M 和 MM_Usr后面的U去掉,
然后 WHERE U.Status=M.Status 改成 WHERE MM_Usr.Status=MM_MerchAcc.Status
Updata From where ?sql有这种写法吗?
还是分成几个UPdate吧,外面加个transaction
有道理