无法绑定多部分标识符 sql
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14621981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
multi part identifier could not be bound sql
提问by Raj
I get multipart can not be bound error on following query
我在以下查询中得到 multipart can not be bound 错误
update nfltx
set
b.boxno = a.boxno,
b.message = a.message,
b.nameboxno = a.nameboxno,
b.namemsg = a.namemsg,
b.phoneboxno = a.phoneboxno,
b.phonemsg = a.phonemsg
FROM ofltx a JOIN nfltx b
ON a.ls_fullnam = b.ls_fullnam
but if i remove b from boxno message and all i do not get the error . What is the reason behind this. Thank You using sql server 2008
但是如果我从 boxno 消息中删除 b 并且所有我都不会收到错误消息。这背后的原因是什么。谢谢使用sql server 2008
回答by Raj
A table alias specified in a FROM clause cannot be used as a qualifier in SET column_name. This is not valid:
在 FROM 子句中指定的表别名不能用作 SET column_name 中的限定符。这是无效的:
update nfltx
set
b.boxno = a.boxno,
b.message = a.message,
b.nameboxno = a.nameboxno,
b.namemsg = a.namemsg,
b.phoneboxno = a.phoneboxno,
b.phonemsg = a.phonemsg
FROM ofltx a JOIN nfltx b
ON a.ls_fullnam = b.ls_fullnam
To make it work, remove the b. alias from the column name.
要使其工作,请删除 b。列名的别名。
update nfltx
set
boxno = a.boxno,
message = a.message,
nameboxno = a.nameboxno,
namemsg = a.namemsg,
phoneboxno = a.phoneboxno,
phonemsg = a.phonemsg
FROM ofltx a JOIN nfltx b
ON a.ls_fullnam = b.ls_fullnam
Raj
拉吉
回答by Damien_The_Unbeliever
What is the reason behind this?
这背后的原因是什么?
An UPDATE
(and DELETE
, INSERT
) can affect one, and only one, table. You've already identified which table you want to affect here:
一个UPDATE
(and DELETE
, INSERT
) 可以影响一个,而且只能影响一个表。您已经在此处确定要影响哪个表:
update nfltx
Therefore, it doesn't make senseto allow an alias for the left hand side of assignments in the SET
clause. They mustbe columns belonging to the previously identified table.
因此,允许子句中赋值左侧的别名是没有意义的SET
。它们必须是属于先前标识的表的列。
If the same table is included in the FROM
clause multiple times (and it's the table you wish to update), you would need to provide an alias to indicate which instance of the table is to be updated - but you'd provide it (once) in the UPDATE
clause rather than in the SET
clause.
如果同一个表FROM
多次包含在子句中(并且它是您希望更新的表),则您需要提供一个别名来指示要更新表的哪个实例 - 但您会提供它(一次)在UPDATE
条款中而不是在SET
条款中。
回答by OneFiveOne
just use
只是使用
update b
instead of
代替
update nfltx
Man you guys make things too difficult for those that are learning.
伙计,你们让那些正在学习的人太难了。