仅更新其他 table 中存在 cust_id 的行
Update only rows where cust_id is present in other table
我有一个查询将显示要匿名化的客户列表:
select cu_number into #_t
from customer
where cu_first_name is not null
我想将 last_name 更新为“'Anonomized' + 序列”并试试这个:
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."
有人知道如何改进子查询吗?
/安德烈亚斯
我认为你根本不需要临时 table:
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
由于答案已在评论中提供,所以我想将其添加为答案。添加 "IN" 而不是 "=" 解决了我遇到的问题。
where cu_number IN (select * from #_t);
谢谢@Jarlh!也感谢其他人提供的重要提示。
我有一个查询将显示要匿名化的客户列表:
select cu_number into #_t
from customer
where cu_first_name is not null
我想将 last_name 更新为“'Anonomized' + 序列”并试试这个:
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."
有人知道如何改进子查询吗?
/安德烈亚斯
我认为你根本不需要临时 table:
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
由于答案已在评论中提供,所以我想将其添加为答案。添加 "IN" 而不是 "=" 解决了我遇到的问题。
where cu_number IN (select * from #_t);
谢谢@Jarlh!也感谢其他人提供的重要提示。