SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SELECT by nvarchar with LIKE multiple whitespaces
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Afroks
Starting Member

1 Posts

Posted - 03/13/2012 :  07:07:51  Show Profile  Reply with Quote
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.

Edited by - Afroks on 03/13/2012 07:12:06

webfred
Flowing Fount of Yak Knowledge

Germany
8514 Posts

Posted - 03/13/2012 :  07:45:08  Show Profile  Visit webfred's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.27 seconds. Powered By: Snitz Forums 2000