Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

search string help needed... Expand / Collapse
Author
Message
Posted Saturday, October 03, 2009 11:56 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, March 17, 2014 6:40 PM
Points: 74, Visits: 263
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

Post #797418
Posted Saturday, October 03, 2009 1:04 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 7:34 AM
Points: 12,744, Visits: 31,077
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
Post #797427
Posted Saturday, October 03, 2009 8:48 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, March 17, 2014 6:40 PM
Points: 74, Visits: 263
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.
Post #797490
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse