Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SELECT by nvarchar with LIKE multiple whitespaces

Author  Topic 

Afroks
Starting Member

1 Post

Posted - 2012-03-13 : 07:07:51
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.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-13 : 07:45:08
PS: Replacing the white spaces is not a solution since I don't know the number of spaces between words.

Replace them on both sides of the LIKE.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -