 




<?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: To retrieve records from SQL Server database</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/to-retrieve-records-from-database/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/to-retrieve-records-from-database/</link>
	<description></description>
	<lastBuildDate>Thu, 23 May 2013 20:47:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/to-retrieve-records-from-database/#comment-59810</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Tue, 10 Feb 2009 15:06:30 +0000</pubDate>
		<guid isPermaLink="false">#comment-59810</guid>
		<description><![CDATA[You are also right Kccrosser, things can get more complicated, and your approach will do the job in such cases.]]></description>
		<content:encoded><![CDATA[<p>You are also right Kccrosser, things can get more complicated, and your approach will do the job in such cases.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kccrosser</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/to-retrieve-records-from-database/#comment-59788</link>
		<dc:creator>kccrosser</dc:creator>
		<pubDate>Tue, 10 Feb 2009 00:19:54 +0000</pubDate>
		<guid isPermaLink="false">#comment-59788</guid>
		<description><![CDATA[Carlosdl - you are correct, for the problem cases shown.  I overlooked that you listed all the distinct cases for start/end of fields and blank separators.

When I have encountered this problem in practice, there is usually a requirement to also find words that may or may not have trailing commas or hyphens (and sometimes where a comma doesn&#039;t have trailing white space, etc.).  I prefer to pre-process the source data to simplify the query and avoid having to enumerate all the possible edge cases.

In a generic environment with the requirement to find &quot;words&quot; that may be surrounded by any combination of space, hyphen, period, and/or comma, the simplest solution I have found is to replace all the &quot;non-text&quot; stuff with a separator character that isn&#039;t in the desired text set and then use that as a start/end symbol when searching the text.

&lt;searchcol&gt; = &#039;&#124;&#039; + replace(replace(replace(replace(&lt;sourcestring&gt;,&#039;,&#039;,&#039;&#124;&#039;),&#039;-&#039;,&#039;&#124;&#039;),&#039;.&#039;,&#039;&#124;&#039;),&#039;&#039;,&#039;&#124;&#039;) +&#039;&#124;&#039;

Then searching with &quot;... where &lt;searchcol&gt; like &#039;%&#124;&#039;+ &lt;word&gt; + &#039;&#124;%&#039; ...&quot;  will find that word, regardless of what non-text characters may precede or follow the word in the original source string.]]></description>
		<content:encoded><![CDATA[<p>Carlosdl &#8211; you are correct, for the problem cases shown.  I overlooked that you listed all the distinct cases for start/end of fields and blank separators.</p>
<p>When I have encountered this problem in practice, there is usually a requirement to also find words that may or may not have trailing commas or hyphens (and sometimes where a comma doesn&#8217;t have trailing white space, etc.).  I prefer to pre-process the source data to simplify the query and avoid having to enumerate all the possible edge cases.</p>
<p>In a generic environment with the requirement to find &#8220;words&#8221; that may be surrounded by any combination of space, hyphen, period, and/or comma, the simplest solution I have found is to replace all the &#8220;non-text&#8221; stuff with a separator character that isn&#8217;t in the desired text set and then use that as a start/end symbol when searching the text.</p>
<p>&lt;searchcol&gt; = &#8216;|&#8217; + replace(replace(replace(replace(&lt;sourcestring&gt;,&#8217;,',&#8217;|'),&#8217;-',&#8217;|'),&#8217;.',&#8217;|'),&#8221;,&#8217;|') +&#8217;|&#8217;</p>
<p>Then searching with &#8220;&#8230; where &lt;searchcol&gt; like &#8216;%|&#8217;+ &lt;word&gt; + &#8216;|%&#8217; &#8230;&#8221;  will find that word, regardless of what non-text characters may precede or follow the word in the original source string.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/to-retrieve-records-from-database/#comment-59765</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Sun, 08 Feb 2009 21:25:14 +0000</pubDate>
		<guid isPermaLink="false">#comment-59765</guid>
		<description><![CDATA[The space would be the separator to find words, there is no need to use an aditional column.  Look at the first part of the answer.]]></description>
		<content:encoded><![CDATA[<p>The space would be the separator to find words, there is no need to use an aditional column.  Look at the first part of the answer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kccrosser</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/to-retrieve-records-from-database/#comment-59744</link>
		<dc:creator>kccrosser</dc:creator>
		<pubDate>Fri, 06 Feb 2009 17:57:14 +0000</pubDate>
		<guid isPermaLink="false">#comment-59744</guid>
		<description><![CDATA[You will not be able to always get the right answer with a &quot;like&quot; query against a text field.
Consider the following case:
&quot;Clean living&quot; - this will satisfy the &#039;%lean %&#039; condition.

The only way to find &quot;words&quot; is to create a second column containing the &quot;words&quot; separated (and preceded/followed!) by a known token, e.g., &quot;&#124;&quot;.

You can do this with a trigger - when records are inserted into the table, generate the separate column with:
&lt;newcol&gt; = &#039;&#124;&#039; + replace(&lt;name&gt;, &#039; &#039;, &#039;&#124;&#039;) + &#039;&#124;&#039;

Then, you can find the &quot;word&quot; of interest using:
select .. where &lt;wordscol&gt; like &#039;%&#124;lean&#124;%&#039;]]></description>
		<content:encoded><![CDATA[<p>You will not be able to always get the right answer with a &#8220;like&#8221; query against a text field.<br />
Consider the following case:<br />
&#8220;Clean living&#8221; &#8211; this will satisfy the &#8216;%lean %&#8217; condition.</p>
<p>The only way to find &#8220;words&#8221; is to create a second column containing the &#8220;words&#8221; separated (and preceded/followed!) by a known token, e.g., &#8220;|&#8221;.</p>
<p>You can do this with a trigger &#8211; when records are inserted into the table, generate the separate column with:<br />
&lt;newcol&gt; = &#8216;|&#8217; + replace(&lt;name&gt;, &#8216; &#8216;, &#8216;|&#8217;) + &#8216;|&#8217;</p>
<p>Then, you can find the &#8220;word&#8221; of interest using:<br />
select .. where &lt;wordscol&gt; like &#8216;%|lean|%&#8217;</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 3/10 queries in 0.050 seconds using memcached
Object Caching 309/315 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-23 21:10:30 -->