<?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: Separate SUM results on a single line</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/separate-sum-results-on-a-single-line/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/separate-sum-results-on-a-single-line/</link>
	<description></description>
	<lastBuildDate>Tue, 18 Jun 2013 21:45:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: peterwarren</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/separate-sum-results-on-a-single-line/#comment-96823</link>
		<dc:creator>peterwarren</dc:creator>
		<pubDate>Tue, 20 Sep 2011 13:14:23 +0000</pubDate>
		<guid isPermaLink="false">#comment-96823</guid>
		<description><![CDATA[Guys, not sure how to &#039;approve&#039; the answer but I haven&#039;t access to the DECODE but Phil&#039;s CASE suggestion worked 9with one minor correction - I needed to name the subquery). 
Many thanks for your help, 
Pete.]]></description>
		<content:encoded><![CDATA[<p>Guys, not sure how to &#8216;approve&#8217; the answer but I haven&#8217;t access to the DECODE but Phil&#8217;s CASE suggestion worked 9with one minor correction &#8211; I needed to name the subquery).<br />
Many thanks for your help,<br />
Pete.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/separate-sum-results-on-a-single-line/#comment-96761</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Mon, 19 Sep 2011 14:08:13 +0000</pubDate>
		<guid isPermaLink="false">#comment-96761</guid>
		<description><![CDATA[You could use the &lt;a href=&quot;http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.sql.ref.doc%2Fdoc%2Fr0000848.html&quot;&gt;SIGN&lt;/a&gt; and &lt;a href=&quot;http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.sql.ref.doc%2Fdoc%2Fr0052622.html&quot;&gt;DECODE&lt;/a&gt; functions, if they are available on your version/platform.

Something like this:

&lt;pre&gt;SELECT 
	branch, 
	SUM(DECODE(SIGN(amount),-1,amount,0)) SUM_NEG,
	SUM(DECODE(SIGN(amount),-1,0,amount)) SUM_POS, 
	COUNT(*)
FROM TableA
...&lt;/pre&gt;

If these functions are not available, you could use a CASE expression.]]></description>
		<content:encoded><![CDATA[<p>You could use the <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.sql.ref.doc%2Fdoc%2Fr0000848.html">SIGN</a> and <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.sql.ref.doc%2Fdoc%2Fr0052622.html">DECODE</a> functions, if they are available on your version/platform.</p>
<p>Something like this:</p>
<pre>SELECT 
	branch, 
	SUM(DECODE(SIGN(amount),-1,amount,0)) SUM_NEG,
	SUM(DECODE(SIGN(amount),-1,0,amount)) SUM_POS, 
	COUNT(*)
FROM TableA
...</pre>
<p>If these functions are not available, you could use a CASE expression.</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/9 queries in 0.013 seconds using memcached
Object Caching 282/285 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-06-18 22:17:30 -->