在SQL Server中将所有出现的单词类型从字符串提取到表中
我有一个表tblExample,它有一个identity列和一个包含HTML数据的列(varchar)clHTML。我需要检查该列中的任何条目,并提取符合此格式的所有单词:“fileName=[word].png” 例如,clHTML的条目可能包含以下内容:在SQL Server中将所有出现的单词类型从字符串提取到表中,sql,sql-server,string,parsing,Sql,Sql Server,String,Parsing,我有一个表tblExample,它有一个identity列和一个包含HTML数据的列(varchar)clHTML。我需要检查该列中的任何条目,并提取符合此格式的所有单词:“fileName=[word].png” 例如,clHTML的条目可能包含以下内容: '/ImageBrowser/GetImage?fileName=ContactUs2.png" /></p><p class="doc-paragraph">A confirmation message wi
'/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'
”/ImageBrowser/GetImage?fileName=ContactUs2.png“/>将显示确认消息,单击确定按钮将完成该过程。
因此,我只希望该条目的表中有ContactUs2.png和ContactUsConfirmation.png。
您需要一个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种。请参阅以下文章
谢谢Prdp!您的解决方案有效,但对于WHERE子句,它起作用:WHERE Split_值,如“%.png%”