But CASE do not work with "< 0" . This is OK (0 is summed as it was 1): SELECT SUM(CASE DISCOUNT WHEN 0 THEN 1 ELSE 0 END) from table
But this one doesn´t work: SELECT SUM(CASE DISCOUNT WHEN < 0 THEN DISCOUNT ELSE 0 END) from table Aílsom Dave Crozier escreveu: > Ailsom, > Look for the "case" statement - should be in all flavours of SQLServer - you > didn't say which you were using > > Dave Crozier > > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf > Of Ailsom F. Heringer (Osklen) > Sent: 21 June 2007 16:08 > To: [email protected] > Subject: SQL question: How to sum ??? > > Foxers, > I have a SQLSERVER table with columns SALE_DATE, SALE_VALUE, DISCOUNT, > TOTAL. I have to sum all columns grouping by date. > (select sale_date,SUM(sale_date),SUM(value),SUM(discount),SUM(total) > from table group by sale_date) > > But, column DISCOUNT, i can sum only negative values (< 0). How can I > sum all values in VALUE and TOTAL and only negative values in DISCOUNT ? > > -- Aílsom F. Heringer [EMAIL PROTECTED] Skype: ailsom.osklen Analista de Sistemas ---------------------------------- Osklen Departamento de Informática Rio de Janeiro - RJ BRASIL http://www.osklen.com.br 55 21 22198971 _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/profox OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED] ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

