To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here

HOME News MS SQL Oracle DB2 Access MySQL PHP Scripts Books Links DBA Talk


Go Back   Database Journal Forums > Related Sites > SQL Course

SQL Course SQL Course > Ask questions about the lessons on SQL Course 1 and 2. If you have problems > with the interface, please post in the Feedback forum

Reply Post New Thread
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 12-09-2002, 11:46 AM
caldas caldas is offline
Junior Member
 
Join Date: Dec 2002
Posts: 1
If

Anybody know how to do this?
I want to creat a SQL Query that SUMS an amout if a condition is positive or SUBTRACT The amout if it is NEGATIVE;
Something like this ( does not work)

SELECT *,SUM(QTD) AS QTT FROM FT GROUP BY REF

What i want is that QTD assumes the value QTD*-1 If a condition occurs , in my case IF CM > 50 (CM is an int number that is on the DB)

Thanks for any help
Reply With Quote
  #2  
Old 12-11-2002, 12:30 PM
skhanal skhanal is offline
Experts
 
Join Date: Nov 2002
Location: New Jersey, USA
Posts: 3,388
If you are only interested in SUM then you can use something like this (it is for Northwind database)

declare @Total numeric
set @Total = 0
select @Total = @Total +
case
when Quantity > 5 then Quantity*-1
else Quantity
end
from [Order Details]
select @Total
Reply With Quote
Reply Post New Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 06:00 PM.


DatabaseJournal Recent Articles


 » Grouping with SQL Server 2008

 » Conducting Service Broker Conversation Usi...

 » SQL Server Consolidation Initiative Under ...

 » Transaction Log Growth, do you need it?

 » New FileMaker Pro 10 Ships With Sleek New ...

Search Database Journal:
 





Acceptable Use Policy

JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.