nel*_*ebs 2 sql stored-procedures sql-server-2008
我有一个这样的数据表.
date, amount, price
2009-10-12, 20, 15.43
2009-10-13, -10, 6.98
Run Code Online (Sandbox Code Playgroud)
我需要编写一个存储过程来返回这些列,并创建一个新列,指示数量是正数还是负数.所以程序的最终结果看起来像这样.
date, amount, price, result
2009-10-12, 20, 15.43, positive
2009-10-13, -10, 6.98, negative
Run Code Online (Sandbox Code Playgroud)
如何才能做到这一点?这是一个sql 2008 ent db.
select date,
amount,
price,
case when amount > 0 then 'positive'
when amount < 0 then 'negative'
end as positive_or_negative
from #table
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
111 次 |
| 最近记录: |