2013-12-20 83 views
0

我有數據庫我找不出如何更新列,因爲它是在每次調用生成的表上。以下是調用相關列的代碼:更新記錄在SQL

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編碼的entrys。我需要運行一個查找和替換來刪除文本之前的html編碼。每個文本之前的HTML代碼是完全一樣的,這裏是需要刪除的內容:<STYLE>H1{font-weight:bold}H1{font-size: 14pt}OL</STYLE><H1>Product Description</H1>

我用@Joel Coehoorn解決方案運行了下面的代碼,並帶有需要更新的內容密鑰,並且它啓動了'消息4104,級別16,狀態1,行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' 

謝謝!

馬特

回答

1

這僅僅是digitalassetcontent.content領域。你應該能夠直接在現場採取行動。什麼是該領域的實際類型?

Update digitalassetcontent 
set content = replace(CAST(d.content as varchar(max)), '<STYLE>H1{font-weight:bold}H1{font-size: 14pt}OL</STYLE><H1>Product Description</H1>','') 
where CAST(d.content as varchar(max)) like '<STYLE>H1{font-weight:bold}H1{font-size: 14pt}OL</STYLE><H1>Product Description</H1>%' 
+0

領域的實際類型是VARBINARY和最大字符長度表示-1 只是讓我可以測試第一,並確保一切是猶太教,我將如何運行上面只是對某一個項目編號和代碼不是所有的項目?例如,我們使用項目編號「AA100」,在我的第一篇文章中初始調用中生成的列名被稱爲「item_no」。 –

+0

@MattWeick我會查找您要測試的特定內容密鑰,而不是項目編號。 –

+0

如果您需要幫助,則可能需要退出數據庫。 –