【发布时间】:2014-01-09 12:50:37
【问题描述】:
我有数据库我不知道如何更新列,因为它位于每次调用生成的表上。以下是调用相关列的代码:
select
a.itm_num as item_no,
a.itm_proddesc as title,
CAST(d.content as varchar(max)) as product_description
from item as a
join assignment as b on b.itm_id = a.itm_id
join attachment as c on c.att_id = b.att_id
join digitalassetcontent as d on d.content_key = c.content_key
where c.att_type like 'text%'
我需要更新 product_description 字段。我们在此列中有数千个条目,这些条目在实际文本前面有 HTML 编码。我需要运行查找和替换以删除文本之前的 html 编码。每个文本前的HTML代码完全一样,这里需要去掉:<STYLE>H1{font-weight:bold}H1{font-size: 14pt}OL</STYLE><H1>Product Description</H1>
我使用@Joel Coehoorn 解决方案运行了以下代码,其中包含我需要更新的内容密钥,它返回了“Msg 4104, Level 16, State 1, Line 13”的错误 无法绑定多部分标识符“d.content”。'
select
a.itm_num as item_no,
a.itm_proddesc as title,
CAST(d.content as varchar(max)) as product_description
from item as a
join assignment as b on b.itm_id = a.itm_id
join attachment as c on c.att_id = b.att_id
join digitalassetcontent as d on d.content_key = c.content_key
where c.att_type like 'text%'
Update digitalassetcontent
set content = replace(CAST(content as varchar(max)), '<STYLE>H1{font-weight:bold}H1{font-size: 14pt}OL</STYLE><H1>Product Description</H1>','')
where CAST(content as varchar(max)) like '<STYLE>H1{font-weight:bold}H1{font-size: 14pt}OL</STYLE><H1>Product Description</H1>%' AND content_key = 'desc214974236480438500781058983745755010'
谢谢!
马特
【问题讨论】:
标签: sql replace sql-update