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)
 IF Statement

Author  Topic 

whitmoj
Yak Posting Veteran

68 Posts

Posted - 2009-01-12 : 05:35:55
I have a sum calc using the following SUM (Presented - TotalHandled) AS AbandonedByFunction, which works fine untill the presented row is 0 then i get a minus number. Can Any one tell me if there is an if statement I can put in front of my Calculation.

Many Thanks


Whitmoj

Whitmoj
If you are in a hurry you will never get there

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-12 : 05:43:16
if(presented>TotalHandled)
SUM (Presented - TotalHandled) AS AbandonedByFunction
else
SUM (TotalHandled - Presented ) AS AbandonedByFunction

Jai Krishna
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-12 : 05:47:40
use case than if for performance level
Go to Top of Page

whitmoj
Yak Posting Veteran

68 Posts

Posted - 2009-01-12 : 05:59:09
JAI
I have already tried this and all I get is Incorrect syntax near the keyword 'if'. and Incorrect syntax near 'SUM'.

Whitmoj
If you are in a hurry you will never get there
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-12 : 06:00:13
if(presented>TotalHandled)
BEGIN
SELECT SUM (Presented - TotalHandled) AS AbandonedByFunction
END
else
BEGIN
SELECT SUM (TotalHandled - Presented ) AS AbandonedByFunction
END


Jai Krishna
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-12 : 07:19:27
select case when Presented > TotalHandled then SUM (Presented - TotalHandled) else sum(TotalHandled - Presented) end AS AbandonedByFunction
from urtable group by Presented
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-12 : 09:15:13
[code]select SUM (ABS(Presented - TotalHandled)) AS AbandonedByFunction
from urtable group by Presented[/code]

Go to Top of Page
   

- Advertisement -