2017-06-19 120 views
2

我有一个表tblExample,它有一个标识列和一个包含HTML数据的列(varchar)clHTML。我需要去通过该列中的任何条目,并提取适合这种格式的话:“png格式文件名= [文字]”从字符串中提取所有出现的字符串到SQL Server中的表格

例如,对于clHTML条目可以有这样的:

'/ImageBrowser/GetImage?fileName=ContactUs2.png" /></p><p class="doc-paragraph">A confirmation message will appear, clicking the OK button will complete the process.</p><p class="doc-paragraph"><img alt="" src="/ImageBrowser/GetImage?fileName=ContactUsConfirmation.png' 

所以我只想在该表项中使用ContactUs2.png和ContactUsConfirmation.png。

回答

1

你需要一个splitstring功能

select left(Split_value,charindex('.png',Split_value)+3) as Result 
from yourtable y 
Cross apply udf_splitstring ss(clHTML,'fileName=') 
Where Split_value like 'fileName=%.png%' 

有很多方法拆分SQL Server中的字符串n个。检查下面的文章

Split strings the right way – or the next best way

Tally OH! An Improved SQL 8K “CSV Splitter” Function

+0

感谢Prdp!你的解决方案工作,但是对于WHERE子句,这可以工作: 其中Split_value像'%.png%' –

相关问题