Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


search string help needed...


search string help needed...

Author
Message
sqlblue
sqlblue
SSC Journeyman
SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)

Group: General Forum Members
Points: 76 Visits: 295
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
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14959 Visits: 38977
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

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

sqlblue
sqlblue
SSC Journeyman
SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)

Group: General Forum Members
Points: 76 Visits: 295
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search