Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First off I think you need an 'ON' clause when joining on the full-text CONTAINSTABLE. See this example from Microsofts website:</p> <pre><code>USE Northwind; GO SELECT FT_TBL.Description, FT_TBL.CategoryName, KEY_TBL.RANK FROM Categories AS FT_TBL INNER JOIN CONTAINSTABLE (Categories, Description, '("sweet and savory" NEAR sauces) OR ("sweet and savory" NEAR candies)' ) AS KEY_TBL ON FT_TBL.CategoryID = KEY_TBL.[KEY] WHERE KEY_TBL.RANK &gt; 2 AND FT_TBL.CategoryName &lt;&gt; 'Seafood' ORDER BY KEY_TBL.RANK DESC; GO </code></pre> <p><a href="http://msdn.microsoft.com/en-us/library/ms177652.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms177652.aspx</a></p> <p>You need to link the Product table to the correct search results by adding a join clause like this:</p> <pre><code>SELECT p.Name AS 'ProductName', m.Name AS 'Manufacturer', r.Rank AS 'Rank' FROM Product p INNER JOIN Manufacturer m ON p.ManufacturerID=m.ID INNER JOIN CONTAINSTABLE(Product, Name, @searchQuery) AS r ON p.ID = r.[KEY] </code></pre> <p>Otherwise you don't known which rows in the results table join to the appropriate rows in the source tables.</p> <p>Secondly, <code>CONTAINS</code> and <code>CONTAINSTABLE</code> both return exact string matches unless you are using wildcards ( e.g. <code>'"bol*"'</code> ). Even when using wildcards you can only use suffix wildcards, so for <code>'"bol*"'</code> it will find all words that start with <code>'bol'</code>. <code>'"*bol*"'</code> will not find words with <code>'bol'</code> in them. For a not-exact, fuzzy style search you should be using <a href="http://msdn.microsoft.com/en-us/library/ms176078.aspx" rel="nofollow noreferrer"><code>FREETEXT( ... )</code></a> or <a href="http://msdn.microsoft.com/en-us/library/ms177652.aspx" rel="nofollow noreferrer"><code>FREETEXTTABLE( ... )</code></a>.</p> <blockquote> <p>Returns a table of zero, one, or more rows for those columns containing character-based data types for values that <strong>match the meaning, but not the exact wording</strong>, of the text in the specified freetext_string. </p> </blockquote> <p><a href="http://msdn.microsoft.com/en-us/library/ms177652.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms177652.aspx</a></p> <p>The trade off is that <code>CONTAINS</code> performs a lot better than <code>FREETEXT</code>, and <code>FREETEXT</code> provides more natural results.</p> <p>Lastly, if you want to match phonetically SQL Server has the built in function SOUNDEX which tries to generate an alphanumerickey based on the phonetic spelling or the argument. </p> <pre><code>-- Using SOUNDEX SELECT SOUNDEX ('Smith'), SOUNDEX ('Smythe'); Copy ----- ----- S530 S530 (1 row(s) affected) </code></pre> <p><a href="http://msdn.microsoft.com/en-us/library/ms187384.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms187384.aspx</a></p> <p>I would advise against using soundex though, I have found it limiting in the past because Soundex really only ensures that to words start off phonetically. Soundex always returns the starting letter and the first three consonant sounds represented numerically. There are better versions of the algorithm out there that were designed as a replacement for soundex, see <a href="http://en.wikipedia.org/wiki/Double_Metaphone" rel="nofollow noreferrer">Double Metaphone</a> (or a <a href="http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=519&amp;lngWId=5" rel="nofollow noreferrer">T-SQL version of Double Metaphone</a> that you can use as a scalar function).</p> <p>Soundex or DoubleMetaphone are not built into SQL Server Fulltext so you would need to implement the search manually. </p> <pre><code>SELECT * FROM MyTable where SOUNDEX( MyColumn ) = SOUNDEX( 'MySearchQuery' ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload