Freelancers Network
 
skill list top cap
Homepage
Join the Freelancer's Network
Update your details
Find a freelancer
Post a project
Find a project
Projects Archive
Post a job
Find a job
Jobs Archive
See Dan's Pages
See Andy's Pages
Link to this site
Resources
Join/Leave Forum
Forum Messages
+Additions+ Adverts
Advertising
Contact Us
Subscribe to our newsletter - enter your email address and hit return
Freelancers.net is owned and operated by Andy Stowell and Dan Winchester
skill list end cap
guru web hostcom

Find me again on Freelancers.net

RE: FN-FORUM: SQL Server Query Problem

date posted 15th January 2004 15:21

Hi,
you wrap the search in quotes

Here's the code from the SQLQuery Analyser Help

--- start ---


CONTAINS
Is a predicate used to search columns containing character-based data
types for precise or fuzzy (less precise) matches to single words and
phrases, the proximity of words within a certain distance of one
another, or weighted matches. CONTAINS can search for:=20

A word or phrase.


The prefix of a word or phrase.


A word near another word.


A word inflectionally generated from another (for example, the word
drive is the inflectional stem of drives, drove, driving, and driven).


A word that has a higher designated weighting than another word.=20
Syntax
CONTAINS
( { column | * } , '< contains_search_condition >'=20
)=20

< contains_search_condition > ::=3D=20
{ < simple_term >=20
| < prefix_term >=20
| < generation_term >=20
| < proximity_term >=20
| < weighted_term >=20
}=20
| { ( < contains_search_condition > )=20
{ AND | AND NOT | OR } < contains_search_condition > [ ...n ]=20
}=20

< simple_term > ::=3D=20
word | " phrase "

< prefix term > ::=3D=20
{ "word * " | "phrase * " }

< generation_term > ::=3D=20
FORMSOF ( INFLECTIONAL , < simple_term > [ ,...n ] )=20

< proximity_term > ::=3D=20
{ < simple_term > | < prefix_term > }=20
{ { NEAR | ~ } { < simple_term > | < prefix_term > } } [ ...n ]=20

< weighted_term > ::=3D=20
ISABOUT=20
( { {=20
< simple_term >=20
| < prefix_term >=20
| < generation_term >=20
| < proximity_term >=20
}=20
[ WEIGHT ( weight_value ) ]=20
} [ ,...n ]=20
)=20

Arguments
column

Is the name of a specific column that has been registered for full-text
searching. Columns of the character string data types are valid
full-text searching columns.

*

Specifies that all columns in the table registered for full-text
searching should be used to search for the given contains search
condition(s). If more than one table is in the FROM clause, * must be
qualified by the table name.=20



Specifies some text to search for in column. Variables cannot be used
for the search condition.

word

Is a string of characters without spaces or punctuation.

phrase

Is one or more words with spaces between each word.=20



Note Some languages, such as those in Asia, can have phrases that
consist of one or more words without spaces between them.


=20

Specifies a match for an exact word (one or more characters without
spaces or punctuation in single-byte languages) or a phrase (one or more
consecutive words separated by spaces and optional punctuation in
single-byte languages). Examples of valid simple terms are "blue berry",
blueberry, and "Microsoft SQL Server". Phrases should be enclosed in
double quotation marks (""). Words in a phrase must appear in the same
order as specified in as they appear in the
database column. The search for characters in the word or phrase is case
insensitive. Noise words (such as a, and, or the) in full-text indexed
columns are not stored in the full-text index. If a noise word is used
in a single word search, SQL Server returns an error message indicating
that only noise words are present in the query. SQL Server includes a
standard list of noise words in the directory
\Mssql\Ftdata\Sqlserver\Config.

Punctuation is ignored. Therefore, CONTAINS(testing, "computer failure")
matches a row with the value, "Where is my computer? Failure to find it
would be expensive."



Specifies a match of words or phrases beginning with the specified text.
Enclose a prefix term in double quotation marks ("") and add an asterisk
(*) before the ending quotation mark, so that all text starting with the
simple term specified before the asterisk is matched. The clause should
be specified this way: CONTAINS (column, '"text*"') The asterisk matches
zero, one, or more characters (of the root word or words in the word or
phrase). If the text and asterisk are not delimited by double quotation
marks, as in CONTAINS (column, 'text*'), full-text search considers the
asterisk as a character and will search for exact matches to text*.

When is a phrase, each word contained in the phrase is
considered to be a separate prefix. Therefore, a query specifying a
prefix term of "local wine *" matches any rows with the text of "local
winery", "locally wined and dined", and so on.

=20

Specifies a match of words when the included simple terms include
variants of the original word for which to search.=20

INFLECTIONAL=20
Specifies that the plural and singular, as well as the gender and
neutral forms of nouns, verbs, and adjectives should be matched. The
various tenses of verbs should be matched too.=20
A given within a will not match both
nouns and verbs.=20



Specifies a match of words or phrases that must be close to one another.
operates similarly to the AND operator: both require
that more than one word or phrase exist in the column being searched. As
the words in appear closer together, the better the
match.=20

NEAR | ~=20
Indicates that the word or phrase on the left side of the NEAR or ~
operator should be approximately close to the word or phrase on the
right side of the NEAR or ~ operator. Multiple proximity terms can be
chained, for example:=20
a NEAR b NEAR c=20

This means that word or phrase a should be near word or phrase b, which
should be near word or phrase c.=20

Microsoft(r) SQL Server(tm) ranks the distance between the left and
right word or phrase. A low rank value (for example, 0) indicates a
large distance between the two. If the specified words or phrases are
far apart from each other, the query is considered to be satisfied;
however, the query has a very low (0) rank value. However, if
consists of only one or more NEAR proximity
terms, SQL Server does not return rows with a rank value of 0. For more
information about ranking, see CONTAINSTABLE.=20



Specifies that the matching rows (returned by the query) match a list of
words and phrases, each optionally given a weighting value.=20

ISABOUT=20
Specifies the keyword.

WEIGHT (weight_value)=20
Specifies a weight value which is a number from 0.0 through 1.0. Each
component in may include a weight_value. weight_value is
a way to change how various portions of a query affect the rank value
assigned to each row matching the query. Weighting forces a different
measurement of the ranking of a value because all the components of
are used together to determine the match. A row is
returned if there is a match on any one of the ISABOUT parameters,
whether or not a weight value is assigned. To determine the rank values
for each returned row that indicates the degree of matching between the
returned rows, see CONTAINSTABLE.=20
AND | AND NOT | OR

Specifies a logical operation between two contains search conditions.
When contains parenthesized groups, these
parenthesized groups are evaluated first. After evaluating parenthesized
groups, these rules apply when using these logical operators with
contains search conditions:=20

NOT is applied before AND.


NOT can only occur after AND, as in AND NOT. The OR NOT operator is not
allowed. NOT cannot be specified before the first term (for example,
CONTAINS (mycolumn, 'NOT "phrase_to_search_for" ' ).


AND is applied before OR.


Boolean operators of the same type (AND, OR) are associative and can
therefore be applied in any order.=20
n

Is a placeholder indicating that multiple contains search conditions and
terms within them can be specified.

Remarks
CONTAINS is not recognized as a keyword if the compatibility level is
less than 70. For more information, see sp_dbcmptlevel.=20

Examples
A. Use CONTAINS with
This example finds all products with a price of $15.00 that contain the
word "bottles."

USE Northwind
GO
SELECT ProductName
FROM Products
WHERE UnitPrice =3D 15.00
AND CONTAINS(QuantityPerUnit, 'bottles')
GO

B. Use CONTAINS and phrase in
This example returns all products that contain either the phrase
"sasquatch ale" or "steeleye stout."

USE Northwind
GO
SELECT ProductName
FROM Products
WHERE CONTAINS(ProductName, ' "sasquatch ale" OR "steeleye stout" ')
GO

C. Use CONTAINS with
This example returns all product names with at least one word starting
with the prefix choc in the ProductName column.

USE Northwind
GO
SELECT ProductName
FROM Products
WHERE CONTAINS(ProductName, ' "choc*" ')
GO

D. Use CONTAINS and OR with
This example returns all category descriptions containing the strings
"sea" or "bread."

USE Northwind
SELECT CategoryName
FROM Categories
WHERE CONTAINS(Description, '"sea*" OR "bread*"')
GO

E. Use CONTAINS with
This example returns all product names that have the word "Boysenberry"
near the word "spread."

USE Northwind
GO
SELECT ProductName
FROM Products
WHERE CONTAINS(ProductName, 'spread NEAR Boysenberry')
GO

F. Use CONTAINS with
This example searches for all products with words of the form dry:
dried, drying, and so on.

USE Northwind
GO
SELECT ProductName
FROM Products
WHERE CONTAINS(ProductName, ' FORMSOF (INFLECTIONAL, dry) ')
GO

G. Use CONTAINS with
This example searches for all product names containing the words spread,
sauces, or relishes, and different weightings are given to each word.

USE Northwind
GO
SELECT CategoryName, Description
FROM Categories
WHERE CONTAINS(Description, 'ISABOUT (spread weight (.8),=20
sauces weight (.4), relishes weight (.2) )' )
GO

H. Use CONTAINS with variables
This example uses a variable instead of a specific search term.

USE pubs
GO
DECLARE @SearchWord varchar(30)
SET @SearchWord =3D'Moon'
SELECT pr_info FROM pub_info WHERE CONTAINS(pr_info, @SearchWord)




--- end ---

=20


Andy
IWD2 LLP
[EMAIL REMOVED]
=20
-----Original Message-----
From: John Kyle [EMAIL REMOVED]
Sent: 15 January 2004 15:49
To: Andy Macnaughton-Jones
Subject: Re: FN-FORUM: SQL Server Query Problem


Hello Andy,

I am still having problems with tSQL - I am using the contains syntax
for full text indexing. When I use the following code:

where [EMAIL REMOVED]

as long as I do not have any spaces I am fine. How can I change this so
I can include a varchar value for @searchStr that allows spaces (I cant
remember how to do this)

Best Regards

John Kyle



--
** Get all the Freelance Work you Can Handle * The Web Design Business
Kit will show you proven tactics and strategies for marketing your
business, winning bids, managing projects and pricing your work. Free
Shipping Worldwide.
Read more & get free chapters at:
http://www.sitepoint.com/launch/b7c91e/3/4

To advertise here: http://www.freelancers.net/advertising.html



Messages by Day
January 31st 2004
January 30th 2004
January 29th 2004
January 28th 2004
January 27th 2004
January 26th 2004
January 25th 2004
January 24th 2004
January 23rd 2004
January 22nd 2004
January 21st 2004
January 20th 2004
January 19th 2004
January 18th 2004
January 17th 2004
January 16th 2004
January 15th 2004
January 14th 2004
January 13th 2004
January 12th 2004
January 11th 2004
January 10th 2004
January 9th 2004
January 8th 2004
January 7th 2004
January 6th 2004
January 5th 2004
January 4th 2004
January 3rd 2004
January 2nd 2004
January 1st 2004


Messages by Month
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
January 2004


Messages by Year
2008
2007
2006
2005
2004
2003
2002
2001
2000