项目中需要提出信息内容中的html的图片路径到一个独立的字段,用程序遍历数据量大的表太费时间
于是用SQL直接在数据进行了筛选提出,利用了SQL的substring 和 partindex 函数使用说明见[转载]SQL截取字符串(substring与patindex的使用) – 爱与决择 – 博客园
代码如下:
--更新商品的缩略图
select identifier,substring(productcontent,patindex('%src="%',ProductContent)+5,PATINDEX('%" />%',productContent)-patindex('%src="%',ProductContent)-5) as pp from Tang_Product where ProductContent like '%src=%' and UserId=13022
--去掉alt
update temp_guojingproductpath
set
pp=substring(pp,0,patindex('%"%',pp))
where
pp like '%"%'
select
pp,substring(pp,0,patindex('%"%',pp))
from temp_guojingproductpath
--更新商品的缩略图
update tang_product
set
ProductImage=pp
from temp_guojingproductpath as p
where
p.identifier=Tang_Product.Identifier and UserId=13022
Mikel