If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > SQL statement - how to 'chop' phrase

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-17-09, 12:55
berkshirea berkshirea is offline
Registered User
 
Join Date: Mar 2009
Posts: 6
SQL statement - how to 'chop' phrase

hi guys how do i do this SQL statements when a user typed in search text field in my ASP.net webpage? How do I 'chop' the typed-in phrases?

examples:

1. typed in phrase: marketing assistant jobs

the resulting SQL statement should be:

SELECT field1,field2
FROM myTable
WHERE CONTAINS(*, 'marketing AND assistant AND jobs')

2. typed in phrase: public administration

the resulting SQL would be:

SELECT field1,field2
FROM myTable
WHERE CONTAINS(*, 'public AND administration')

3. typed in phrase: SQL server full text search
result would be:

SELECT field1,field2
FROM myTable
WHERE CONTAINS(*, 'SQL AND server AND full AND text AND search')



thanks for any ideas.

.
Reply With Quote
  #2 (permalink)  
Old 12-17-09, 13:09
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,307
This actually need sto be done before SQL Server even sees the data. Each of the .NET languages has diffent string handling functions, so there isn't a "one size fits all" solution.

I'll move this thread to the ASP forum for you. It will probably get better answers there.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #3 (permalink)  
Old 12-17-09, 19:17
myle myle is offline
(Making Your Life Easy)
 
Join Date: Feb 2004
Location: New Zealand
Posts: 1,110
What i Done done is join all the feilds you want to search in to make a New Feild

then use the WHERE


Whereis = "WHERE newsearchfeild Like '%" & Searchingfor & "%'"
__________________
hope this help

See clear as mud


StePhan McKillen
the aim is store once, not store multiple times
Progaming environment:
Access based on my own environment: DAO3.6/A97/A2000/A2003
VB based on my own environment: vb6 sp5
ASP based on my own environment: 5.6
VB-NET based on my own environment started 2007
SQL-2005 based on my own environment started 2008
MYLE
Reply With Quote
  #4 (permalink)  
Old 12-22-09, 08:04
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,002
It seems that replacing spaces (" ") with " AND " would give you a pretty good start...
Code:
--Initialise parameter
DECLARE @parameter varchar(100)
SET @parameter = 'marketing assistant jobs'

--Perform the replace
SET @parameter = Replace(@parameter, ' ', ' AND ')

--And then search...
SELECT field1,field2
FROM myTable
WHERE CONTAINS(*, @parameter)
__________________
George
Twitter | Blog
Reply With Quote
  #5 (permalink)  
Old 12-23-09, 05:23
berkshirea berkshirea is offline
Registered User
 
Join Date: Mar 2009
Posts: 6
Quote:
Originally Posted by gvee View Post
It seems that replacing spaces (" ") with " AND " would give you a pretty good start...
Code:
--Initialise parameter
DECLARE @parameter varchar(100)
SET @parameter = 'marketing assistant jobs'

--Perform the replace
SET @parameter = Replace(@parameter, ' ', ' AND ')

--And then search...
SELECT field1,field2
FROM myTable
WHERE CONTAINS(*, @parameter)
hi gvee, thanks for the suggestion, it's working when you are searching words or phrases without 'AND' and 'OR' but when i have search phrases with 'AND' or 'OR' for example 'sun and moon' or 'my way or highway' it gives error. i searched to resolve this issue but i'm stuck. any ideas?
Reply With Quote
  #6 (permalink)  
Old 12-23-09, 05:37
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,002
Why not remove/replace the "and"s from the initial string before replacing the spaces?
Code:
SET @parameter = Replace(@parameter, 'and', '&')
SET @parameter = Replace(@parameter, ' ', ' AND ')
__________________
George
Twitter | Blog
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On