views:

49

answers:

1

I have a table of data something like this.

date, amount, price
2009-10-12, 20, 15.43
2009-10-13, -10, 6.98

I need to write a stored procedure that will return these column as well as create a new column that indicates whether the amount was positive or negative. So the end result of the procedure would look something like this.

date, amount, price, result
2009-10-12, 20, 15.43, positive
2009-10-13, -10, 6.98, negative

How can this be done? This is a sql 2008 ent db.

+5  A: 
select  date, 
        amount, 
        price, 
        case when amount > 0 then 'positive' 
             when amount < 0 then 'negative' 
        end as positive_or_negative
from #table
ryanulit
+1: Added missing single quote at the end of `negative`
OMG Ponies
+1: No sense having two of the same answer.
ChaosPandion
Thanks, changed it when I reformatted. :)
ryanulit
+1 for trapping "zero" (even as NULL output)
gbn
yep, that will do the job. Thanks guys
nelsonwebs