Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Adding up negative figures

Author  Topic 

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2009-08-20 : 08:23:52
Hi i've a a qty column which have negitave figures in it some times.
Example

qty Type
6 A
1 A
1 A
1 A
6 A
-2 B
--
17 Total

No you may think its strange to add the -2 but i do need to show this
now do i get sql to add the -1 once the type column is set to B if i have a negative number.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-20 : 08:27:10
Did not get you.
What is your problem / wanted output?

Edit: What do you mean with "add the -1"?

No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2009-08-20 : 08:40:00
select sum(abs(qty)) from table

select sum(
case when type='B' then -qty
else qty ) from table
Go to Top of Page
   

- Advertisement -