合并语句的问题(特别是更新部分)



我在使合并命令工作时遇到问题。我发现的是,它不允许一次更新多个列。有什么办法吗?

出现的错误是

"Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "s.AddressCaption" could not be bound."

我肯定服务器和列都存在并且命名正确。如果我尝试删除 S.AddressCaption,那么下一列是弹出的错误。

它似乎只识别 s.descr

下面是查询:

MERGE Payor as T
Using dss.RCSQL.dbo.Payors as S
ON t.code = s.code
WHEN MATCHED and (s.descr <> t.descr or s.AddressCaption <> t.[AddressCaption] or S.Address <> t.address or S.address2 <> t.address2 or 
s.city <> t.city or s.state <> t.state or s.zip <> t.zip or s.ContactPhone <> t.ContactPhone or s.systemID <> t.systemID or s.notes <> t.notes or
s.notes <> t.notes or s.fax <> t.fax or s.medicarepart <> t.medicarepart or s.category <> t.category or s.PayorKey <> t.Payorkey)
THEN
UPDATE SET t.descr = s.descr, s.AddressCaption = t.[AddressCaption],  S.Address = t.address,  S.address2 = t.address2,  
s.city = t.city,  s.state = t.state,  s.zip = t.zip,  s.ContactPhone = t.ContactPhone,  s.systemID = t.systemID,  s.notes = t.notes, 
s.notes = t.notes,  s.fax = t.fax,  s.medicarepart = t.medicarepart,  s.category = t.category,  s.PayorKey = t.Payorkey
WHEN NOT MATCHED THEN 
INSERT (code,descr, [AddressCaption], Address, Address2, City, State, Zip, ContactPhone, systemID, Notes, Fax, MedicarePart, category, PayorKey)
VALUES (s.code,s.descr, s.AddressCaption, s.Address, s.Address2, s.City, s.State, s.Zip, s.ContactPhone, s.systemID, 
s.Notes, s.Fax, s.MedicarePart, s.category, s.PayorKey);

Dave.Gugg的解决方案是与具有目标表保持一致。属性],然后是源表。【属性】第二。

t.col1 = s.col1, t.col2 = s.col2 ...

相关内容

最新更新