SQLTeam.com | Weblogs | Forums

Change numeric to negative if column condition is true



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.


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


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