<?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: Using a Case Statement in a SQL Where Clause</title> <atom:link href="http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/feed/" rel="self" type="application/rss+xml" /><link>http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/</link> <description>Tech, Love, Life</description> <lastBuildDate>Fri, 18 May 2012 16:27:45 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>By: Dhiraj</title><link>http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/comment-page-1/#comment-65809</link> <dc:creator>Dhiraj</dc:creator> <pubDate>Thu, 23 Jun 2011 06:10:16 +0000</pubDate> <guid isPermaLink="false">/archive/2007/07/31/Using-a-Case-Statement-in-a-SQL-Where-Clause.aspx#comment-65809</guid> <description>Your comment is awaiting moderation.What if i want to change the condition Why is some thing like below not possible? where var1 case when comparer = ‘G’ then =  -- change condition here end &#039;conditionvalue&#039;</description> <content:encoded><![CDATA[<p>Your comment is awaiting moderation.</p><p>What if i want to change the condition<br /> Why is some thing like below not possible?<br /> where var1<br /> case when comparer = ‘G’ then<br /> =  &#8212; change condition here<br /> end<br /> &#8216;conditionvalue&#8217;</p> ]]></content:encoded> </item> <item><title>By: Dhiraj</title><link>http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/comment-page-1/#comment-65808</link> <dc:creator>Dhiraj</dc:creator> <pubDate>Thu, 23 Jun 2011 06:09:17 +0000</pubDate> <guid isPermaLink="false">/archive/2007/07/31/Using-a-Case-Statement-in-a-SQL-Where-Clause.aspx#comment-65808</guid> <description>What if i want to change the condition Why is some thing like below not possible? where var1 case when comparer = &#039;G&#039;  then &lt;= else &lt;= end &#039;conditionvalue&#039;</description> <content:encoded><![CDATA[<p>What if i want to change the condition<br /> Why is some thing like below not possible?<br /> where var1<br /> case when comparer = &#8216;G&#8217;  then<br /> &lt;=<br /> else<br /> &lt;=<br /> end<br /> &#039;conditionvalue&#039;</p> ]]></content:encoded> </item> <item><title>By: kralco626</title><link>http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/comment-page-1/#comment-63256</link> <dc:creator>kralco626</dc:creator> <pubDate>Thu, 09 Jun 2011 11:49:41 +0000</pubDate> <guid isPermaLink="false">/archive/2007/07/31/Using-a-Case-Statement-in-a-SQL-Where-Clause.aspx#comment-63256</guid> <description>Not sure its a Coincidence... :p</description> <content:encoded><![CDATA[<p>Not sure its a Coincidence&#8230; :p</p> ]]></content:encoded> </item> <item><title>By: Loralei</title><link>http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/comment-page-1/#comment-49145</link> <dc:creator>Loralei</dc:creator> <pubDate>Fri, 25 Feb 2011 20:11:44 +0000</pubDate> <guid isPermaLink="false">/archive/2007/07/31/Using-a-Case-Statement-in-a-SQL-Where-Clause.aspx#comment-49145</guid> <description>Thanks so much for this post!  I read another one that said a case statment was not possible in a where clause, but I actually really had the need for it.  So, now my query gets me exactly what I need.</description> <content:encoded><![CDATA[<p>Thanks so much for this post!  I read another one that said a case statment was not possible in a where clause, but I actually really had the need for it.  So, now my query gets me exactly what I need.</p> ]]></content:encoded> </item> <item><title>By: Scott</title><link>http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/comment-page-1/#comment-11332</link> <dc:creator>Scott</dc:creator> <pubDate>Fri, 08 Jan 2010 10:17:52 +0000</pubDate> <guid isPermaLink="false">/archive/2007/07/31/Using-a-Case-Statement-in-a-SQL-Where-Clause.aspx#comment-11332</guid> <description>that doesn&#039;t look like you can use a case statement.  just a huge if...ou just need a lot of parenthesis and all your &quot;and&quot;&#039;&#039;s should be &quot;or&quot;&#039;s since you cant have a record that has both status=pay and status=approval at the same time.WHERE ((status = ‘pay’ and reason is null) OR (status = ‘approval’ and reason is null)) AND ((status = ‘exception’ and reason is not null) OR (status = ‘exception’ and reason1 is not null) OR (status = ‘exception’ and reason2 is not null))</description> <content:encoded><![CDATA[<p>that doesn&#8217;t look like you can use a case statement.  just a huge if&#8230;ou just need a lot of parenthesis and all your &#8220;and&#8221;&#8221;s should be &#8220;or&#8221;&#8216;s since you cant have a record that has both status=pay and status=approval at the same time.</p><p>WHERE<br /> ((status = ‘pay’ and reason is null)<br /> OR (status = ‘approval’ and reason is null))<br /> AND<br /> ((status = ‘exception’ and reason is not null)<br /> OR (status = ‘exception’ and reason1 is not null)<br /> OR (status = ‘exception’ and reason2 is not null))</p> ]]></content:encoded> </item> <item><title>By: Val</title><link>http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/comment-page-1/#comment-11291</link> <dc:creator>Val</dc:creator> <pubDate>Wed, 06 Jan 2010 18:49:04 +0000</pubDate> <guid isPermaLink="false">/archive/2007/07/31/Using-a-Case-Statement-in-a-SQL-Where-Clause.aspx#comment-11291</guid> <description>I&#039;m trying to use Case in the where clause, but I&#039;m new to SQL and am not sure if that will even work or how to make it work with what I desire.What I desire is below...can anyone help?Where status = &#039;pay&#039; and reason is null and status = &#039;approval&#039; reason is null and status = &#039;exception&#039; and reason is not null and status = &#039;exception&#039; and reason1 is not null and status = &#039;exception&#039; and reason2 is not null</description> <content:encoded><![CDATA[<p>I&#8217;m trying to use Case in the where clause, but I&#8217;m new to SQL and am not sure if that will even work or how to make it work with what I desire.</p><p>What I desire is below&#8230;can anyone help?</p><p>Where<br /> status = &#8216;pay&#8217; and reason is null<br /> and status = &#8216;approval&#8217; reason is null<br /> and status = &#8216;exception&#8217; and reason is not null<br /> and status = &#8216;exception&#8217; and reason1 is not null<br /> and status = &#8216;exception&#8217; and reason2 is not null</p> ]]></content:encoded> </item> <item><title>By: Nits</title><link>http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/comment-page-1/#comment-10367</link> <dc:creator>Nits</dc:creator> <pubDate>Mon, 16 Nov 2009 14:04:13 +0000</pubDate> <guid isPermaLink="false">/archive/2007/07/31/Using-a-Case-Statement-in-a-SQL-Where-Clause.aspx#comment-10367</guid> <description>Hi, Thank for the code, i really need this type of functionaliy, thanks again...!!!</description> <content:encoded><![CDATA[<p>Hi, Thank for the code, i really need this type of functionaliy, thanks again&#8230;!!!</p> ]]></content:encoded> </item> <item><title>By: Nateg</title><link>http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/comment-page-1/#comment-9568</link> <dc:creator>Nateg</dc:creator> <pubDate>Thu, 24 Sep 2009 22:09:17 +0000</pubDate> <guid isPermaLink="false">/archive/2007/07/31/Using-a-Case-Statement-in-a-SQL-Where-Clause.aspx#comment-9568</guid> <description>Thanks for the post.  Been trying to do some things with a similar situation at work and found this helpful.Coincidentally, you can put a case statement on both sides of the = sign like so:where case (boolean) then (expression) else (expression) end = case (boolean) then (expression) else (expression) endAs long as both sides of the operator have valid syntax.</description> <content:encoded><![CDATA[<p>Thanks for the post.  Been trying to do some things with a similar situation at work and found this helpful.</p><p>Coincidentally, you can put a case statement on both sides of the = sign like so:</p><p>where<br /> case (boolean) then (expression) else (expression) end =<br /> case (boolean) then (expression) else (expression) end</p><p>As long as both sides of the operator have valid syntax.</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)

Served from: scottelkin.com @ 2012-05-22 04:40:17 -->
