 




<?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: composite WHERE condition in SQL Server</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/composite-where-condition/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/composite-where-condition/</link>
	<description></description>
	<lastBuildDate>Wed, 22 May 2013 05:05:11 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: marcw</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/composite-where-condition/#comment-71496</link>
		<dc:creator>marcw</dc:creator>
		<pubDate>Fri, 11 Dec 2009 08:59:11 +0000</pubDate>
		<guid isPermaLink="false">#comment-71496</guid>
		<description><![CDATA[Okay...  I don&#039;t have any control over the table, this is an MIS application pulling from a database someone else has created.  What we&#039;re pulling from is actually a snapshot: would it be better to ask them to create a field in the snapshot that&#039;s pre-formatted?]]></description>
		<content:encoded><![CDATA[<p>Okay&#8230;  I don&#8217;t have any control over the table, this is an MIS application pulling from a database someone else has created.  What we&#8217;re pulling from is actually a snapshot: would it be better to ask them to create a field in the snapshot that&#8217;s pre-formatted?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mrdenny</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/composite-where-condition/#comment-71473</link>
		<dc:creator>mrdenny</dc:creator>
		<pubDate>Fri, 11 Dec 2009 03:16:38 +0000</pubDate>
		<guid isPermaLink="false">#comment-71473</guid>
		<description><![CDATA[While you can do this keep in mind that any indexes that you have on the table won&#039;t be used.  You&#039;ll get better performance if you add a computed column and index that column then use that column in your WHERE clause.]]></description>
		<content:encoded><![CDATA[<p>While you can do this keep in mind that any indexes that you have on the table won&#8217;t be used.  You&#8217;ll get better performance if you add a computed column and index that column then use that column in your WHERE clause.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/composite-where-condition/#comment-71445</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Thu, 10 Dec 2009 17:27:29 +0000</pubDate>
		<guid isPermaLink="false">#comment-71445</guid>
		<description><![CDATA[Since you are using concatenations and conversions in your where clause,  the optimizer is not using any indexes and is already doing a full table scan to get your data, so, I think you could avoid the double conversion by doing something like this:

&lt;pre&gt;SELECT code, ver
FROM ( 
SELECT code, right(’0′ + convert(VARCHAR,codeversion),2) AS ver
FROM table) AS temp
where code+ver IN (’00102′,’00202′,’00302′);&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Since you are using concatenations and conversions in your where clause,  the optimizer is not using any indexes and is already doing a full table scan to get your data, so, I think you could avoid the double conversion by doing something like this:</p>
<pre>SELECT code, ver
FROM ( 
SELECT code, right(’0′ + convert(VARCHAR,codeversion),2) AS ver
FROM table) AS temp
where code+ver IN (’00102′,’00202′,’00302′);</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: marcw</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/composite-where-condition/#comment-71443</link>
		<dc:creator>marcw</dc:creator>
		<pubDate>Thu, 10 Dec 2009 16:39:10 +0000</pubDate>
		<guid isPermaLink="false">#comment-71443</guid>
		<description><![CDATA[Thanks- that works.  

In this instance, the version field is a derived field, because the field in the database is an 11-char int for some reason.

So it looks like this:

SELECT code, right(&#039;0&#039; + convert(VARCHAR,codeversion),2) AS ver
FROM table 
WHERE 
code + right(&#039;0&#039; + convert(VARCHAR,codeversion),2) IN (&#039;00102&#039;,&#039;00202&#039;,&#039;00302&#039;) ;

If I use WHERE code + ver IN (&#039;00102&#039;,&#039;00202&#039;,&#039;00302&#039;) as the predicate, the SQL Server ODBC driver complains that &quot;ver&quot; is an invalid field name.

I&#039;m concerned that it&#039;s inefficient doing the conversion multiple times.  Am I missing a trick here?]]></description>
		<content:encoded><![CDATA[<p>Thanks- that works.  </p>
<p>In this instance, the version field is a derived field, because the field in the database is an 11-char int for some reason.</p>
<p>So it looks like this:</p>
<p>SELECT code, right(&#8217;0&#8242; + convert(VARCHAR,codeversion),2) AS ver<br />
FROM table<br />
WHERE<br />
code + right(&#8217;0&#8242; + convert(VARCHAR,codeversion),2) IN (&#8217;00102&#8242;,&#8217;00202&#8242;,&#8217;00302&#8242;) ;</p>
<p>If I use WHERE code + ver IN (&#8217;00102&#8242;,&#8217;00202&#8242;,&#8217;00302&#8242;) as the predicate, the SQL Server ODBC driver complains that &#8220;ver&#8221; is an invalid field name.</p>
<p>I&#8217;m concerned that it&#8217;s inefficient doing the conversion multiple times.  Am I missing a trick here?</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.039 seconds using memcached
Object Caching 309/315 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-22 07:26:58 -->