开发者

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

开发者 https://www.devze.com 2023-01-18 15:12 出处:网络
I have this query: select * from table where column like \'%firstword[something]secondword[something]thirdword%\'

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

精彩评论

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

关注公众号