SQLTeam.com | Weblogs | Forums

Change numeric to negative if column condition is true


#1

Hi,

My database field, trans_amt, is storing positive values for certain rows. I need to modify the query below to display it as negative in those cases where the check_no field is empty.

SELECT a.fund,a.key_orgn,a.account,a.trans_date,a.t_c,a.check_no,a.trans_amt,a.[description] as description
FROM transact a
WHERE a.account = @account AND a.trans_date >= @startdate and a.trans_date <= @enddate
ORDER BY a.trans_date desc

Your help is greatly appreciated. thank you.


#2

Change
a.trans_amt ,
to
CASE WHEN a.check_no IS NULL THEN -a.trans_amt ELSE a.trans_amt END AS trans_amt ,


#3

Hey, thanks a lot. I was thinking a CASE statement did it.