无法绑定由多个部分组成的标识符
with temp as
(
select branchGuid, n.branchname,right(b.branchname,len(b.branchname)-3) brname from branch b
inner join old o on b.branchname=o.branchname
inner join new n on right(o.branchname,len(o.branchname)-3)=right(n.branchname,len(n.branchname)-3)
)
--select temp.branchGuid from temp
update branch set branch.branchname=temp.branchname where temp.branchGuid=branch.branchGuid
上句会报错 无法绑定由多个部分组成的标识符 temp
下面是正确的写法
with temp as
(
select branchGuid, n.branchname,right(b.branchname,len(b.branchname)-3) brname from branch b
inner join old o on b.branchname=o.branchname
inner join new n on right(o.branchname,len(o.branchname)-3)=right(n.branchname,len(n.branchname)-3)
)
--select temp.branchGuid from temp
update branch set branch.branchname=temp.branchname from branch,temp where temp.branchGuid=branch.branchGuid
问题分析,属于逻辑问题,按照update 表1 set xxx=xxx from 表1,表2 where XXX.XXX=XXX.XXX
跨数据库访问时
with temp as
(
select branchGuid, n.branchname bn,b.branchname br,right(b.branchname,len(b.branchname)-3) brname from branch b
inner join [192.1xx.xxx.xxx].mydrp.dbo.old o on b.branchname=o.branchname
inner join [192.1xx.xxx.xxx].mydrp.dbo.new n on right(o.branchname,len(o.branchname)-3)=right(n.branchname,len(n.branchname)-3)
)
--select br,bn, temp.branchGuid from temp
update branch set branch.branchname=t.bn from branch,temp t where t.branchGuid=branch.branchGuid
此处如果将t.bn换为t.branchname会报错(无法绑定由多个部分组成的标识符 )