Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SELECT record by nvarchar with LIKE when the criteria contains multiple whitespaces

$
0
0
I need to write a select query by nvarchar. For instance the query so far looks like this:

SELECT * FROM Reservations.BlockResource WHERE Reason LIKE '%'+ @Reason+ '%'


However the problem is that the reason might have multiple whitespaces since it is nvarchar. If the @Reason='Blocked for John Doe. He is coming at 5pm', the query works. But if @Reason='Blocked for John Doe. He is coming at______5pm', the query wont work cause of the multiple spaces between words.
I would really appreciate if someone could share a workaround for this issue. 

Thank you in advance

PS: Replacing the white spaces is not a solution since I don't know the number of spaces between words.

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>