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.
| Author |
Topic |
|
kanchan
Starting Member
1 Post |
Posted - 2007-11-02 : 02:31:44
|
| Hi,I have to write a SQL Query. The codition is like suppose u have three coloums id,type,amount. And you have to do sum n minus operation in the same query based on the type value. for example id type amount1 A 1002 A 1003 A 4004 B 200Now i need to compute total amount.like if the type is 'A' then add that to total and if type is 'B' then minus the same from the total.The output for the above should be = 400 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-11-02 : 02:35:08
|
[code]select sum(case when type = 'A' then amount when type = 'B' then -amount end)from yourtable[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|