开发者

Use like in T-SQl to search for words separated by an unknown number of spaces

I have this query:

select * from table where column like '%firstword[something]secondword[something]thirdword%'

What do I replace [something] with to match an unknown number of spaces?

Edited to add: % will not work as it开发者_Go百科 matches any character, not just spaces.


Perhaps somewhat optimistically assuming "unknown number" includes zero.

select * 
from table where 
REPLACE(column_name,' ','') like '%firstwordsecondwordthirdword%'


The following may help: http://blogs.msdn.com/b/sqlclr/archive/2005/06/29/regex.aspx as it describes using regular expressions in SQL queries in SQL Server 2005


I would definitely suggest cleaning the input data instead, but this example may work when you call it as a function from the SELECT statement. Note that this will potentially be very expensive.

http://www.bigresource.com/MS_SQL-Replacing-multiple-spaces-with-a-single-space-9llmmF81.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜