 




<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to find a specific word in a SQL table</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/how-to-find-a-specific-word-in-a-sql-table/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/how-to-find-a-specific-word-in-a-sql-table/</link>
	<description></description>
	<lastBuildDate>Mon, 20 May 2013 18:21:12 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: tomliotta</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/how-to-find-a-specific-word-in-a-sql-table/#comment-92980</link>
		<dc:creator>tomliotta</dc:creator>
		<pubDate>Tue, 07 Jun 2011 01:08:56 +0000</pubDate>
		<guid isPermaLink="false">#comment-92980</guid>
		<description><![CDATA[Since some parts of an answer might change, what database product is being used?

Tom]]></description>
		<content:encoded><![CDATA[<p>Since some parts of an answer might change, what database product is being used?</p>
<p>Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kccrosser</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/how-to-find-a-specific-word-in-a-sql-table/#comment-92970</link>
		<dc:creator>kccrosser</dc:creator>
		<pubDate>Mon, 06 Jun 2011 18:48:25 +0000</pubDate>
		<guid isPermaLink="false">#comment-92970</guid>
		<description><![CDATA[I would suggest using a function to do the &quot;hard&quot; logic.

Use a simple query to find the records containing the substring of interest, then apply the function to those to get just the ones where the substring is a &quot;word&quot;.
&lt;pre&gt;declare sSubString varchar(255);
declare sWildCardString varchar(255);

set sSubString = &#039;bob&#039;;
set sWildCardString = &#039;%&#039; + sSubString + &#039;%&#039;;

SELECT *
FROM YourTable
WHERE Column like sWildCardString
and MyFunction(sSubString, Column) = 1&lt;/pre&gt;

The logic for the function is actually pretty simple:

&lt;pre&gt;function MyFunction (
psSubString varchar(255),
psSourceString varchar(max))
return integer
begin
	declare i integer;
	declare iFound integer;
	set i = 1;
	set iFound = 0;
	while i &gt; 0 and iFound = 0
	begin
		set i = CHARINDEX(psSubString, sSourceString, i);
		if i &gt; 0
		begin
			set iFound = 1;
			if i &gt; 1 and CHARINDEX(substring(sSourceString,i,1),&#039;abcdefghijklmnopqrstuvwxyz&#039;) &gt; 0
			set iFound = 0;
			if i &lt; length(sSourceString) and CHARINDEX(substring(sSourceString,i+length(sSubString),1),&#039;abcdefghijklmnopqrstuvwxyz&#039;) &gt; 0
			set iFound = 0;
		end;
		set i = i + 1;
	end;
	return iFound;
end;&lt;/pre&gt;

The function finds EACH occurrence of the substring (might be more than one), then checks to make sure that the occurrence is not preceded or followed by an alpha character, which will handle any typical embedded text substrings.]]></description>
		<content:encoded><![CDATA[<p>I would suggest using a function to do the &#8220;hard&#8221; logic.</p>
<p>Use a simple query to find the records containing the substring of interest, then apply the function to those to get just the ones where the substring is a &#8220;word&#8221;.</p>
<pre>declare sSubString varchar(255);
declare sWildCardString varchar(255);

set sSubString = 'bob';
set sWildCardString = '%' + sSubString + '%';

SELECT *
FROM YourTable
WHERE Column like sWildCardString
and MyFunction(sSubString, Column) = 1</pre>
<p>The logic for the function is actually pretty simple:</p>
<pre>function MyFunction (
psSubString varchar(255),
psSourceString varchar(max))
return integer
begin
	declare i integer;
	declare iFound integer;
	set i = 1;
	set iFound = 0;
	while i &gt; 0 and iFound = 0
	begin
		set i = CHARINDEX(psSubString, sSourceString, i);
		if i &gt; 0
		begin
			set iFound = 1;
			if i &gt; 1 and CHARINDEX(substring(sSourceString,i,1),'abcdefghijklmnopqrstuvwxyz') &gt; 0
			set iFound = 0;
			if i &lt; length(sSourceString) and CHARINDEX(substring(sSourceString,i+length(sSubString),1),'abcdefghijklmnopqrstuvwxyz') &gt; 0
			set iFound = 0;
		end;
		set i = i + 1;
	end;
	return iFound;
end;</pre>
<p>The function finds EACH occurrence of the substring (might be more than one), then checks to make sure that the occurrence is not preceded or followed by an alpha character, which will handle any typical embedded text substrings.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 6/8 queries in 0.017 seconds using memcached
Object Caching 283/284 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-20 20:50:38 -->