If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Searching by ignoring special characters

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-14-11, 08:54
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,280
Searching by ignoring special characters

Hi,

In our schools we have a number of East-European, Turkish, Scandinavian, ... students. Their names contain "special" characters, like Ö, Ü, Ø, ... Our users want to be able to search for student names without having to enter those special characters. Most often they don't know the exact spelling of the names and they get "no match found" messages as a result.

They want to have persons with the name Ösgür, Osgueld, ... in the result set after entering "osgu" in the search field.

What is the best way to do this?
I was thinking about using another collation near the LIKE, but I don't know if that would work and how it should be done. The Database collation is Latin1_General_CI_AS.
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
Reply With Quote
  #2 (permalink)  
Old 12-14-11, 10:40
weejas weejas is offline
Registered User
 
Join Date: Sep 2006
Location: Surrey, UK
Posts: 448
Bloody users and their requirements...

Perhaps a customised Soundex function would help here? It might be a hassle to write, but it would then be easy to update in the event of new characters appearing. I have one in VBA that could be amended and translated in T-SQL, probably.
__________________
10% of magic is knowing something that no-one else does. The rest is misdirection.
Reply With Quote
  #3 (permalink)  
Old 12-14-11, 12:39
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
Code:
DECLARE @c			NVARCHAR(99)

SET @c = 'Ösgür'

SELECT
   CASE WHEN @c LIKE N'Osg%'
      THEN 'Yes'
      ELSE 'No'
   END AS Naked
,  CASE WHEN @c COLLATE Latin1_General_CI_AI LIKE N'Osg%'
      THEN 'Yes'
      ELSE 'No'
   END AS Fancy
-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #4 (permalink)  
Old 12-14-11, 15:10
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,280
Pat,

Thanks a lot!

Latin1_General_CI_AS
- CI stands for Case Insensitive
- AS for Accent Sensitive

Latin1_General_CI_AI
- AI stands for Accent Insensitive. For me an accent is something like é or è, I didn't realise it also includes Ö, Ü and the likes.
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

Last edited by Wim; 12-14-11 at 15:30.
Reply With Quote
  #5 (permalink)  
Old 12-14-11, 15:12
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,280
Quote:
Originally Posted by weejas View Post
Bloody users and their requirements...


I could see their point in this case.
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On