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 |
abacusdotcom
Posting Yak Master
133 Posts |
Posted - 2011-05-31 : 10:16:40
|
Dear All,Thanks for help as usual.Kindly see below:DECLARE @trans_tbl table (tran_id int, tran_date int, credit_amt money, debit_amt money )insert into @trans_tbl (tran_id, tran_date, credit_amt, debit_amt)select 1, 2011-04-01, -2.00, 0.00 UNION ALLselect 2, 2011-04-02, 0.00, 500.00 UNION ALLselect 3, 2011-04-09, -54.00, 900.00 UNION ALLselect 4, 2011-04-19, -20.00, 0.00 UNION ALLselect 5, 2011-04-22, 0.00, 0.00 UNION ALLselect 6, 2011-04-30, 0.00, 343.00 UNION ALLMy Expected Resulttran_id tran_date Amount Type1 2011-04-01 -2.00 Liability2 2011-04-02 500.00 Asset3 2011-04-09 -54.00 Liability3 2011-04-09 900.00 Asset4 2011-04-19 -20.00 Liability5 2011-04-22 0.00 Asset6 2011-04-30 343.00 AssetKindly note, - tran_id 3 return both figures - tran_id 5 returns 0.00 (If possible the record can be exempted)Many thanks.I sign for fame not for shame but all the same, I sign my name. |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-05-31 : 10:26:43
|
select tran_id, tran_date, credit_amt as Amount,CASE WHEN credit_amt > 0 Then 'Asset' Else 'Liability' End as [Type]from @trans_tbl where credit_amt <> 0union select tran_id, tran_date, debit_amt as Amount,CASE WHEN debit_amt > 0 Then 'Asset' Else 'Liability' End as [Type]from @trans_tbl where debit_amt <> 0JimEveryday I learn something that somebody else already knew |
 |
|
abacusdotcom
Posting Yak Master
133 Posts |
Posted - 2011-06-01 : 04:25:05
|
Thanks Boss Jim... Very grateful...I sign for fame not for shame but all the same, I sign my name. |
 |
|
|
|
|
|
|