gpt4 book ai didi

sql-server - Sql Server 替换功能

转载 作者:行者123 更新时间:2023-12-04 05:33:15 25 4
gpt4 key购买 nike

我正在尝试运行以下语句,但它没有按预期工作。

它旨在获取子查询值并将其从注释字段中删除(替换为空字符串)。

我已经检查过子查询返回了我期望的正确值,但替换函数没有像我期望的那样工作。有人会有什么想法吗?

提前谢谢你。

update contacts set comment = 
replace(comment,
(select 'Specialty: ' + a.categoryname
from contacts c
join categories a
on c.categorycode = a.categorycode
where contacts.contactid = c.contactid)
, '')

最佳答案

我猜应该这样做

update contacts 
set comment = replace(comment,'Speciality :' + categories.categoryname,'')
from contacts inner join categories
on contacts.categorycode=categories.categorycode
and contacts.contactid=categories.contactid

in sqlfiddle

关于sql-server - Sql Server 替换功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12309960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com