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

I have this query:

select * from the table where the column is of type '% firstword [something] secondword [something] thirdword%'

What should I replace [something] with an unknown number of spaces?

Edited to add:% will not work because it matches any character, not just spaces.

+4
source share
3 answers

Perhaps somewhat optimistic in assuming that the “unknown number” includes zero.

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

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

+1
source

I would definitely suggest clearing the input, but this example may work when you call it as a function from the SELECT . Please note that this will potentially be very expensive.

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

0
source

All Articles