I'm working at a web site search which uses Sql server 2008 express edition.
I have 'Books' table which has a field named 'Title' where there are titles containing romanian (latin) characters.
Well, if the user inserts a word like: 'casa' in the search field and i have a title in db like: 'test casă test' i want to show that book but:
select * from books where title like '%casa%'
will not find it...
Do you know any function which removes the diacritics when doing the select?
I know that i can solve the problem with full text searching add-on of sql server but i want to do it in a simpler way.
Names can contain only alphanumeric characters and must begin with an alphabetic character or an underscore (_). Database names must begin with an alphabetic character, and cannot begin with an underscore.
CONTAINS is a predicate used in the WHERE clause of a Transact-SQL SELECT statement to perform SQL Server full-text search on full-text indexed columns containing character-based data types. CONTAINS can search for: A word or phrase. The prefix of a word or phrase.
select * from books where title COLLATE Latin1_General_CI_AI like '%casa%'
Of course, you should choose a collation that matches yours... just change AS to AI on the end to make it "accent insensitive"
Quick example with German umlauts
DECLARE @foo TABLE (bar varchar(100) /*implied COLLATE Latin1_General_CI_AS*/)
INSERT @foo VALUES ('xxx fish yyy')
INSERT @foo VALUES ('xxx bar yyy' )
INSERT @foo VALUES ('xxx bär yyy')
select * from @foo where bar COLLATE Latin1_General_CI_AI like '%bar%'
select * from @foo where bar like '%bar%'
You need to use an accent insensitive collate clause.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With