March 26, 2023 at 12:19 am
what I want is to apply some filter patterns to search the data. For example. There is a large physical table in the database regarding medicines, I want to allow search even if user write lasix, lasixx, lasixxx, lasax, lasi, lisax. Data should be retrieved for the medicine lasix. How can I write these filter patterns in SQL query? And this query should be compilent with old SQL server versions like 2008 as well. I want to do it in SQL Server side instead of c# logic. Help and assistance is really appreciated.
March 27, 2023 at 1:10 am
Thanks for posting your issue and hopefully someone will answer soon.
This is an automated bump to increase visibility of your question.
March 27, 2023 at 5:12 am
This was removed by the editor as SPAM
March 27, 2023 at 9:31 am
SOUNDEX is going to be the closest thing in T-SQL to do it, but it wouldn't match LASIX to LASI as the sound isn't the same.
Just note it's non-SARGable so will cripple your performance.
Best this is done in C# / Application code.
create table #temp (string varchar(10))
insert into #temp values
('lasix'),
('lasixx'),
('lasixxx'),
('lasax'),
('lasi'),
('lisax')
declare @searchstring varchar(10) = 'lasix'
select string,@searchstring
from #temp
where soundex(string) = soundex(@searchstring)
March 27, 2023 at 2:28 pm
If this is a user search that's coming from a UI, can you create a translation table?
What about full text search?
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
March 28, 2023 at 12:29 am
Thank you everyone.
Yes it is coming through UI and user can enter anything in it
March 28, 2023 at 12:49 am
Ok, then can this be a pick list? Eliminate the human error.
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
March 28, 2023 at 1:57 am
Everybody wants to search for things like Google does. Go buy a product that will do this for you in SQL server... it'll be cheaper that you trying to build one that doesn't actually work well. Some will recommend full text search (built into sql server) and (ugh!) SOUNDEX and you can try those but, ultimately, I think that's going to lead to disappointment. Go buy a product to do it.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply