|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Saturday, March 02, 2013 4:14 PM
Points: 69,
Visits: 218
|
|
Hi, I need help in getting the result back from the search based on the criteria as follow: 1) if the user type in the text box the words 'rest again' without any quotes around them (the single quotes I put around them here just to differentiate them from the rest), the result should come back as rest OR again OR resting is fine. But nothing should come back that stand before the word rest (so, antirest and anti-rest should not come back from the result).
2) if the user type "rest again" in the box (with the double quotes around them as shown) , the result should come back as the whole 2 words 'rest again' (again, the single quote i put around them here just to differentiate from the rest).
Any idea would be appreciated.
the sample is below.
create table test ( id int not null, string varchar(100) NULL )
GO insert into test select 1, 'rest' union select 2, 'resting experience' union select 3, 'rest again' union select 4, 'anti-rest' union select 5, 'antirest'
GO
create procedure proc_test ( @string varchar(100) ) as
select * from test where string LIKE '% ' + @string + ' %' OR string LIKE ' ' + @string + '%' OR string LIKE @string + '%'
--drop table test --drop procedure proc_test
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 9:56 AM
Points: 11,619,
Visits: 27,681
|
|
there's a great article here on SSC on creating a google like full text search, which does everything you are asking and more; I'd suggest going that way first, as it would make your searches much more robust and professional.
Lowell
--There is no spoon, and there's no default ORDER BY in sql server either. Actually, Common Sense is so rare, it should be considered a Superpower. --my son
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Saturday, March 02, 2013 4:14 PM
Points: 69,
Visits: 218
|
|
Thanks Lowell for the link. It is very helpful. I couldn't understand completely his code, but what helped me was to look into SQL Server 2008 Full Text Indexing option, which has already been available in earlier versions, but I totally forgot about it. Thanks again.
|
|
|
|