﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Globalization / SQL Server 7,2000  / Need help with SQL Code (for basic site search) / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 16:33:07 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Need help with SQL Code (for basic site search)</title><link>http://www.sqlservercentral.com/Forums/Topic1416605-230-1.aspx</link><description>Oh yes you're right, it's code for MySQL, so don't think your fix would work for that unfortunately?</description><pubDate>Wed, 06 Feb 2013 10:12:07 GMT</pubDate><dc:creator>scott231us</dc:creator></item><item><title>RE: Need help with SQL Code (for basic site search)</title><link>http://www.sqlservercentral.com/Forums/Topic1416605-230-1.aspx</link><description>Scott i suspect you posted some code for MYSQL and not SQL Server.In SQLServer, the best solution is to enable Full Text Indexing, and use that;for exact word match, but any order, i posted this example a long time ago, which was using dynamic SQL to build a query for search terms; unfortunately, this kind of query isslow, since it requires a table scan. That might be acceptable for small tables, but the more data, the more this would suffer performance wise:example results:[quote]WHERE CHARINDEX('civil',YOURTABLE.COLUMNNAME) &amp;gt; 0   OR CHARINDEX('war',YOURTABLE.COLUMNNAME) &amp;gt; 0   OR CHARINDEX('memorabilia',YOURTABLE.COLUMNNAME) &amp;gt; 0   OR CHARINDEX('equipment',YOURTABLE.COLUMNNAME) &amp;gt; 0[/quote][code]--better formatDECLARE @SEARCHSTRING    VARCHAR(8000),        @ALLSEARCHTERMS  VARCHAR(8000),        @SOMESEARCHTERMS VARCHAR(8000),        @COLUMNNAME      VARCHAR(128),        @vbCrLf          CHAR(2)SET @SEARCHSTRING='civil war memorabilia equipment'SET @COLUMNNAME = 'YOURTABLE.COLUMNNAME'SET @vbCrLf = CHAR(13) + CHAR(10)SELECT @ALLSEARCHTERMS =  'WHERE CHARINDEX(''' + REPLACE(@SEARCHSTRING,' ',''',' + @COLUMNNAME + ') &amp;gt; 0 ' + @vbCrLf + '  AND CHARINDEX(''') + ''',' + @COLUMNNAME + ') &amp;gt; 0' + @vbCrLf, @SOMESEARCHTERMS =  'WHERE CHARINDEX(''' + REPLACE(@SEARCHSTRING,' ',''',' + @COLUMNNAME + ') &amp;gt; 0 ' + @vbCrLf + '  OR CHARINDEX(''') + ''',' + @COLUMNNAME + ') &amp;gt; 0' + @vbCrLfSELECT @ALLSEARCHTERMSSELECT @SOMESEARCHTERMS[/code]</description><pubDate>Wed, 06 Feb 2013 09:58:28 GMT</pubDate><dc:creator>Lowell</dc:creator></item><item><title>Need help with SQL Code (for basic site search)</title><link>http://www.sqlservercentral.com/Forums/Topic1416605-230-1.aspx</link><description>Hi, the basic search on my site is too specific..  Meaning it's too exact with word order and phrases.For example, if I search Shoes Red it won't show results for Red Shoes.If you search for Red Shoe Laces it won't show results for Red Laces (as the word shoe throws off this order).  Below is the code that I believe the search box is using.  Can anyone tell me how to "loosen" up this search so it's either more broad or so exact word order isn't necessary?This is the current code:case 'search':	    				if (intval($filter) != 0) {	    					$filter = JString::strtolower($filter);	    					$id = intval($filter);	    					$search .= $temp."(a.id = $id OR LOWER(a.ad_headline) LIKE '%".$this-&amp;gt;_db-&amp;gt;getEscaped($filter,true)."%' OR LOWER(a.ad_text) LIKE '%".$this-&amp;gt;_db-&amp;gt;getEscaped($filter,true)."%')";	    				} else {	    					$filter = JString::strtolower($filter);	    					$search .= $temp."(LOWER(a.ad_headline) LIKE '%".$this-&amp;gt;_db-&amp;gt;getEscaped($filter,true)."%' OR LOWER(a.ad_text) LIKE '%".$this-&amp;gt;_db-&amp;gt;getEscaped($filter,true)."%')";	    				}	    				break;	    		}	    	}    	}    	return $search;    }Any ideas here?</description><pubDate>Wed, 06 Feb 2013 09:44:49 GMT</pubDate><dc:creator>scott231us</dc:creator></item></channel></rss>