显示标签为“follows”的博文。显示所有博文
显示标签为“follows”的博文。显示所有博文

2012年3月27日星期二

Full Text Search with a Parameter

I have a Full Text query that works fine when structured as follows:

SELECT First_Name, Middle_Name, Last_Name, Hire_Date, City, Department, Phone_Ext, title, Fax, Secretary_Name, Attorney_Name, Secy_Ext, Home_Phone, Desk_Location, Law_School, Undergraduate_School, Languages, E_mail, CMS_ID, WEB_ID, Notary

FROM dbo.PhotoDir

WHERE CONTAINS (*, 'Jones')

ORDER BY Last_Name, First_Name

However, I would like to replace "Jones" with a parameter, @.LName for example. However, I can't figure out the syntax. I tried the following:

WHERE CONTAINS (*, @.LName)

but received the following error:

The @.LName SQL construct or statement is not supported.

Is there a way to put a parameter in this type of query?

Thanks in advance.

Hi There,

Have a look at this article, mnight give you a clue on what you doing there.

http://technet.microsoft.com/en-us/library/ms187787.aspx

Hope it helps!

|||

Hi lwhalen618,

See this example in sql2005 online book:

USE AdventureWorks;GODECLARE @.SearchWord nvarchar(30)SET @.SearchWord = N'Performance'SELECT Description FROM Production.ProductDescription WHERE CONTAINS(Description, @.SearchWord);GO

See, it's totally fine to use parameter within full-text-indexing. Your code seems okay to me. Please check if you have declared @.LName in your code.

Hope my suggestione helps

|||

I was able to get my code to work using a stored procedure. The query builder within VS2005 would not let me use the additional code before the Select statement.

Thanks for your help.

2012年3月26日星期一

Full Text Search of terms including asterisks

I have a document containing the term *sosos

Searching for this with different levels of wildcard placement results as follows:

1 CONTAINS([TargetField] , ' "*sosos"') results in 1 item

2 CONTAINS([TargetField] , ' "*sosos*"') results in 1 item

3 CONTAINS([TargetField] , ' "*soso*"') results in 1 item

4 CONTAINS([TargetField] , ' "*sos*"') results in 1 item

5 CONTAINS([TargetField] , ' "*so*"') results in anything where a term starts with SO

6 CONTAINS([TargetField] , ' "*s*"') results many more where a term starts with S

7 CONTAINS([TargetField] , ' "**"') results in nothing retrieved

Searches 1-4 result in what I would expect. Searches 5-7 do not. Is this a bug or am I missing something?

The * can only be used as a suffix not a prefix.

Have a look at my post

Generally * are treated as noise and so removed that is why you are gettnig the results you are