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
SQL CourseSQL 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
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)
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