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 > Database Server Software > Microsoft SQL Server > help with CONTAINS syntax

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-06-12, 13:16
mrpcguy mrpcguy is offline
Registered User
 
Join Date: Mar 2004
Posts: 140
help with CONTAINS syntax

How do i write this query "CONTAINS (text, 'FORMSOF(INFLECTIONAL, something)',LANGUAGE 1033)" if i want to replace the word "something" with a varaibel?

just replace the word with variabel like "CONTAINS (text, 'FORMSOF(INFLECTIONAL, @freetext)',LANGUAGE 1033)" does not work.


Thanks in advance
Reply With Quote
  #2 (permalink)  
Old 01-06-12, 15:27
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
Is the first example posted in the BOL entry for CONTAINS what you want?

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #3 (permalink)  
Old 01-06-12, 15:41
mrpcguy mrpcguy is offline
Registered User
 
Join Date: Mar 2004
Posts: 140
yes kind of... this works fine"CONTAINS(Description, @SearchWord)" but i also want the "'FORMSOF(INFLECTIONAL, @freetext)',LANGUAGE 1033)" part. But i can't find the correct syntax.
Reply With Quote
  #4 (permalink)  
Old 01-06-12, 15:50
mrpcguy mrpcguy is offline
Registered User
 
Join Date: Mar 2004
Posts: 140
my bad

i want example "H. Using CONTAINS with variables" with "(text, 'FORMSOF(INFLECTIONAL, @freetext)',LANGUAGE 1033)" part
Reply With Quote
  #5 (permalink)  
Old 01-13-12, 15:56
mrpcguy mrpcguy is offline
Registered User
 
Join Date: Mar 2004
Posts: 140
i ask in another way.

How can i use CONTAINS with variabel and search with multiple words?

I use CONTAINS in a WHERE statement and it works just fine with one search word or if i use AND OR NOT NEAR, no problem. But if i write "word1 word2" i got error:
Msg 7630, Level 15, State 3, Procedure...

how can i avoid this error message when people search like i described?
i have tried to put in this to get rid of some stuff the users put in to separate the search criteria the use:
set @search = replace(@search, '?','*')
set @search = replace(@search, '!','*')
set @search = replace(@search, ',','*')
set @search = replace(@search, ';','*')
set @search = replace(@search, '/','*')
set @search = replace(@search, ':','*')

To get rid of the error message when they put in blanks (or if the row contains NULL) i use:
IF ISNULL(@p_search,'') = '' SET @search= '""';

How can i achieve this?
1. Get rid of the error message when they put in "wrong" search statement?
2. Make the users to be able to search for multiple words in one string?


thx in advance
Reply With Quote
  #6 (permalink)  
Old 01-13-12, 17:09
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #7 (permalink)  
Old 01-14-12, 04:27
mrpcguy mrpcguy is offline
Registered User
 
Join Date: Mar 2004
Posts: 140
yes FREETEXT works fine with multiple words but not so well with Boolean search expression's.
Is there any way to have both Boolean search with multiple words?
Reply With Quote
  #8 (permalink)  
Old 01-16-12, 12:40
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
Do you mean like example J in CONTAINS (Transact-SQL) ???

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #9 (permalink)  
Old 01-16-12, 13:25
mrpcguy mrpcguy is offline
Registered User
 
Join Date: Mar 2004
Posts: 140
im trying to get a google-like search.
Where i can put in Boolean search expression like OR, AND, NEAR and also single words like [dbforums phelan AND pat]
Reply With Quote
  #10 (permalink)  
Old 01-16-12, 16:59
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
The problem is that [dbforums phelan AND pat] is in fact a perfectly legitimate search expression. It parses into two string operands and an AND operator.

Is that what you want, or did you expect three strings and two operators. If you expected another operator, which one (AND, OR, NOT, NEAR) did you expect?

The problem comes from trying to match English (or any spoken language) to a parsable logical expression. There isn't always a clear one-to-one match between them and unfortunately computers usually require that simple-minded one-to-one match in order to work well.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #11 (permalink)  
Old 01-17-12, 03:00
mrpcguy mrpcguy is offline
Registered User
 
Join Date: Mar 2004
Posts: 140
thanks for the effort.

In my mind i have expect the string like [dbforums AND phelan AND pat] so that menas that blanks should be AND and everything else whichever operator i put in (AND, OR, NOT NEAR) and even search for exact phrases like "dbforums pat phelan" using quotation marks.
Reply With Quote
  #12 (permalink)  
Old 01-20-12, 04:34
mrpcguy mrpcguy is offline
Registered User
 
Join Date: Mar 2004
Posts: 140
Can anyone give me a hint or push me in right direction reagarding this?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On