我有一个查询将显示要匿名的客户列表:
select cu_number into #_t
from customer
where cu_first_name is not null
我想将last_name更新为“'Anonomized'+sequence”并尝试这个:
update customer
set cu_last_name = 'Anonomized' + convert(varchar, cu_number)
where cu_number = (select * from #_t);
我收到以下错误,并且似乎无法找到解决此问题的合适方法:
"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression."
有人知道如何改进子查询吗?
/安德烈亚斯
最佳答案
我认为你根本不需要临时表:
update customer set cu_last_name='Anonomized' + convert(char, cu_number)
where cu_first_name is not null
在 MySQL
中,您不能将 convert
函数与 varchar
类型一起使用。
对于Sql Server
:
update customer set cu_last_name='Anonomized' + convert(varchar(10), cu_number)
where cu_first_name is not null
关于sql - 仅更新其他表中存在 cust_id 的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30618618/