<p><strong>Note:</strong> I <em>am</em> using SQL's Full-text search capabilities, CONTAINS clauses and all - the * is the wildcard in full-text, % is for LIKE clauses only.</p>

<p>I've read in several places now that "leading wildcard" searches (e.g. using "*overflow" to match "stackoverflow") is not supported in MS SQL.  I'm considering using a <a href="http://blogs.msdn.com/sqlclr/archive/2005/06/29/regex.aspx" rel="noreferrer" title="SQL CLR Blog">CLR function to add regex matching</a>, but I'm curious to see what other solutions people might have.</p>

<p><strong>More Info</strong>: <a href="http://msdn.microsoft.com/en-us/library/ms552152.aspx" rel="noreferrer" title="MSDN">You can add the asterisk only at the end of the word or phrase.</a> - along with my empirical experience:  When matching "myvalue", "my*" works, but "(asterisk)value" returns no match, when doing a query as simple as:</p>

<pre><code>SELECT * FROM TABLENAME WHERE CONTAINS(TextColumn, '"*searchterm"');
</code></pre>

<p>Thus, my need for a workaround.  I'm only using search in my site on an actual search page - so it needs to work basically the same way that Google works (in the eyes on a Joe Sixpack-type user). Not nearly as complicated, but this sort of match really shouldn't fail.</p>

[{'answer_id': 3405, 'author': 'Kev', 'author_id': 419, 'author_profile': 'https://Stackoverflow.com/users/419', 'pm_score': 2, 'selected': False, 'text': "<p><strong>Note</strong>: this was the answer I submitted for the original version #1 of the question before the <code>CONTAINS</code> keyword was introduced in revision #2. It's still factually accurate.</p>\n<p>The wildcard character in SQL Server is the <code>%</code> sign and it works just fine, leading, trailing or otherwise.</p>\n<p>That said, if you're going to be doing any kind of serious full text searching then I'd consider utilising the Full Text Index capabilities. Using <code>%</code> and <code>_</code> wild cards will cause your database to take a serious performance hit.</p>\n"}, {'answer_id': 3413, 'author': 'GateKiller', 'author_id': 383, 'author_profile': 'https://Stackoverflow.com/users/383', 'pm_score': -1, 'selected': False, 'text': "<p>% Matches any number of characters\n    _ Matches a single character</p>\n\n<p>I've never used Full-Text indexing but you can accomplish rather complex and fast search queries with simply using the build in T-SQL string functions.</p>\n"}, {'answer_id': 3422, 'author': 'Dave Ward', 'author_id': 60, 'author_profile': 'https://Stackoverflow.com/users/60', 'pm_score': 2, 'selected': False, 'text': '<p>One thing worth keeping in mind is that leading wildcard queries come at a significant performance premium, compared to other wildcard usages.</p>\n'}, {'answer_id': 3427, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 4, 'selected': False, 'text': "<p>The problem with leading Wildcards: They cannot be indexed, hence you're doing a full table scan.</p>\n"}, {'answer_id': 3521, 'author': 'Otto', 'author_id': 519, 'author_profile': 'https://Stackoverflow.com/users/519', 'pm_score': -1, 'selected': False, 'text': '<p>From SQL Server Books Online:</p>\n\n<blockquote>\n  <p>To write full-text queries in\n  Microsoft SQL Server 2005, you must\n  learn how to use the CONTAINS and\n  FREETEXT Transact-SQL predicates, and\n  the CONTAINSTABLE and FREETEXTTABLE\n  rowset-valued functions.</p>\n</blockquote>\n\n<p>That means all of the queries written above with the % and _ are not valid full text queries.</p>\n\n<p>Here is a sample of what a query looks like when calling the CONTAINSTABLE function.</p>\n\n<blockquote>\n  <p>SELECT    RANK    , * FROM    TableName   ,\n  CONTAINSTABLE (TableName, *, \'\n  "*WildCard" \') searchTable WHERE\n    [KEY] = TableName.pk ORDER BY \n    searchTable.RANK DESC</p>\n</blockquote>\n\n<p>In order for the CONTAINSTABLE function to know that I\'m using a wildcard search, I have to wrap it in double quotes.  I can use the wildcard character * at the beginning or ending.  There are a lot of other things you can do when you\'re building the search string for the CONTAINSTABLE function.  You can search for a word near another word, search for inflectional words (drive = drives, drove, driving, and driven), and search for synonym of another word (metal can have synonyms such as aluminum and steel).</p>\n\n<p>I just created a table, put a full text index on the table and did a couple of test searches and didn\'t have a problem, so wildcard searching works as intended.</p>\n\n<p>[Update]</p>\n\n<p>I see that you\'ve updated your question and know that you need to use one of the functions.</p>\n\n<p>You can still search with the wildcard at the beginning, but if the word is not a full word following the wildcard, you have to add another wildcard at the end.</p>\n\n<pre><code>Example:  "*ildcar" will look for a single word as long as it ends with "ildcar".\n\nExample:  "*ildcar*" will look for a single word with "ildcar" in the middle, which means it will match "wildcard".  [Just noticed that Markdown removed the wildcard characters from the beginning and ending of my quoted string here.]\n</code></pre>\n\n<p>[Update #2]</p>\n\n<p>Dave Ward - Using a wildcard with one of the functions shouldn\'t be a huge perf hit.  If I created a search string with just "*", it will not return all rows, in my test case, it returned 0 records.</p>\n'}, {'answer_id': 6078, 'author': 'Sean Carpenter', 'author_id': 729, 'author_profile': 'https://Stackoverflow.com/users/729', 'pm_score': 0, 'selected': False, 'text': '<p>When it comes to full-text searching, for my money nothing beats <a href="http://lucene.apache.org" rel="nofollow noreferrer">Lucene</a>.  There is a <a href="http://incubator.apache.org/projects/lucene.net.html" rel="nofollow noreferrer">.Net port available</a> that is compatible with indexes created with the Java version.</p>\n\n<p>There\'s a little work involved in that you have to create/maintain the indexes, but the search speed is fantastic and you can create all sorts of interesting queries.  Even indexing speed is pretty good - we just completely rebuild our indexes once a day and don\'t worry about updating them.</p>\n\n<p>As an example, <a href="http://www.wateronline.com/Search.mvc?keyword=wastewater" rel="nofollow noreferrer">this search functionality</a> is powered by Lucene.Net.</p>\n'}, {'answer_id': 68207, 'author': 'user9569', 'author_id': 9569, 'author_profile': 'https://Stackoverflow.com/users/9569', 'pm_score': 1, 'selected': False, 'text': "<p>Just FYI, Google does not do any substring searches or truncation, right or left.  They have a wildcard character * to find unknown words in a phrase, but not a word.   </p>\n\n<p>Google, along with most full-text search engines, sets up an inverted index based on the alphabetical order of words, with links to their source documents.  Binary search is wicked fast, even for huge indexes.  But it's really really hard to do a left-truncation in this case, because it loses the advantage of the index.  </p>\n"}, {'answer_id': 124502, 'author': 'xnagyg', 'author_id': 2622295, 'author_profile': 'https://Stackoverflow.com/users/2622295', 'pm_score': 5, 'selected': False, 'text': '<p>Workaround only for leading wildcard:</p>\n\n<ul>\n<li>store the text reversed in a different field (or in materialised view)</li>\n<li>create a full text index on this column</li>\n<li><p>find the reversed text with an *</p>\n\n<pre><code>SELECT * \nFROM TABLENAME \nWHERE CONTAINS(TextColumnREV, \'"mrethcraes*"\');\n</code></pre></li>\n</ul>\n\n<p>Of course there are many drawbacks, just for quick workaround...</p>\n\n<p>Not to mention CONTAINSTABLE...</p>\n'}, {'answer_id': 320132, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>It is possible to use the wildcard "*" at the end of the word or phrase (prefix search).</p>\n\n<p>For example, this query will find all "datab", "database", "databases" ...</p>\n\n<pre><code>SELECT * FROM SomeTable WHERE CONTAINS(ColumnName, \'"datab*"\')\n</code></pre>\n\n<p>But, unforutnately, it is not possible to search with leading wildcard.</p>\n\n<p>For example, this query will not find "database"</p>\n\n<pre><code>SELECT * FROM SomeTable WHERE CONTAINS(ColumnName, \'"*abase"\')\n</code></pre>\n'}, {'answer_id': 7678692, 'author': 'Forrest', 'author_id': 982752, 'author_profile': 'https://Stackoverflow.com/users/982752', 'pm_score': 2, 'selected': False, 'text': '<p>To perhaps add clarity to this thread, from my testing on 2008 R2, Franjo is correct above. When dealing with full text searching, at least when using the CONTAINS phrase, you cannot use a leading <em>, only a trailing</em> functionally. * is the wildcard, not % in full text.</p>\n\n<p>Some have suggested that * is ignored. That does not seem to be the case, my results seem to show that the trailing * functionality does work. I think leading * are ignored by the engine.</p>\n\n<p>My added problem however is that the same query, with a trailing *, that uses full text with wildcards worked relatively fast on 2005(20 seconds), and slowed to 12 minutes after migrating the db to 2008 R2. It seems at least one other user had similar results and he started a forum post which I added to...   FREETEXT works fast still, but something "seems" to have changed with the way 2008 processes trailing * in CONTAINS. They give all sorts of warnings in the Upgrade Advisor that they "improved" FULL TEXT so your code may break, but unfortunately they do not give you any specific warnings about certain deprecated code etc. ...just a disclaimer that they changed it, use at your own risk. </p>\n\n<p><a href="http://social.msdn.microsoft.com/Forums/ar-SA/sqlsearch/thread/7e45b7e4-2061-4c89-af68-febd668f346c" rel="nofollow">http://social.msdn.microsoft.com/Forums/ar-SA/sqlsearch/thread/7e45b7e4-2061-4c89-af68-febd668f346c</a></p>\n\n<p>Maybe, this is the closest MS hit related to these issues... <a href="http://msdn.microsoft.com/en-us/library/ms143709.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms143709.aspx</a></p>\n'}, {'answer_id': 34602059, 'author': 'ASP Force', 'author_id': 3464788, 'author_profile': 'https://Stackoverflow.com/users/3464788', 'pm_score': 1, 'selected': False, 'text': '<p>As a parameter in a stored procedure you can use it as:</p>\n\n<pre><code>ALTER procedure [dbo].[uspLkp_DrugProductSelectAllByName]\n(\n    @PROPRIETARY_NAME varchar(10)\n)\nas\n    set nocount on\n    declare @PROPRIETARY_NAME2 varchar(10) = \'"\' + @PROPRIETARY_NAME + \'*"\'\n\n    select ldp.*, lkp.DRUG_PKG_ID\n    from Lkp_DrugProduct ldp\n    left outer join Lkp_DrugPackage lkp on ldp.DRUG_PROD_ID = lkp.DRUG_PROD_ID\n    where contains(ldp.PROPRIETARY_NAME, @PROPRIETARY_NAME2)\n</code></pre>\n'}, {'answer_id': 40114596, 'author': 'LogicalMan', 'author_id': 6460524, 'author_profile': 'https://Stackoverflow.com/users/6460524', 'pm_score': 0, 'selected': False, 'text': '<p>Perhaps the following link will provide the final answer to this use of wildcards: <a href="https://blogs.msdn.microsoft.com/sqlforum/2011/02/27/faq-how-can-i-perform-wildcard-searches-in-full-text-search/" rel="nofollow">Performing FTS Wildcard Searches</a>.</p>\n\n<p>Note the passage that states: "However, if you specify “<em>Chain” or “Ch</em>ain”, you will not get the expected result. The asterisk will be considered as a normal punctuation mark not a wildcard character. "</p>\n'}, {'answer_id': 51138309, 'author': 'Hans', 'author_id': 9989507, 'author_profile': 'https://Stackoverflow.com/users/9989507', 'pm_score': 0, 'selected': False, 'text': '<p>If you have access to the list of words of the full text search engine, you could do a \'like\' search on this list and match the database with the words found, e.g. a table \'words\' with following words:</p>\n\n<pre><code>    pie\n    applepie\n    spies\n    cherrypie\n    dog\n    cat\n</code></pre>\n\n<p>To match all words containing \'pie\' in this database on a fts table \'full_text\' with field \'text\':</p>\n\n<pre><code>    to-match &lt;- SELECT word FROM words WHERE word LIKE \'%pie%\'\n    matcher = ""\n    a = ""\n    foreach(m, to-match) {\n      matcher += a\n      matcher += m\n      a = " OR "\n    }\n    SELECT text FROM full_text WHERE text MATCH matcher\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/3400', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/35/']