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 |
|
my_my
Starting Member
2 Posts |
Posted - 2010-11-04 : 06:53:16
|
| I have a table whose columns areProject_name , segment, Debit ,Credit, (Dr-Cr) Balance Now my requirement is that if segment start with 4 its expense and if it starts with 5 its revenue now I need separate balance column for each expense and revenue Kindly help me in this regard how I can do this |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-11-04 : 06:59:59
|
Please post DDL, sample data and wanted result. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
kvbc85
Starting Member
2 Posts |
Posted - 2010-11-04 : 07:06:10
|
| its require more descriptions |
 |
|
|
my_my
Starting Member
2 Posts |
Posted - 2010-11-04 : 07:06:32
|
| i have made this query but i need separate balance columns for revenue and expense how can i do that??SELECT get_flex_description('1013605',cc.segment4) proj, CASE WHEN cc.segment5 like '4%' THEN cc.segment5 ELSE NULL END expense, CASE WHEN cc.segment5 like '5%' THEN cc.segment5 ELSE NULL END revenue, sum(bl.project_to_date_dr_beq) Dr,sum(bl.project_to_date_cr_beq) Cr, sum((bl.project_to_date_dr_beq - bl.project_to_date_cr_beq)) Balance from gl_balances bl,gl_code_combinations ccwhere bl.code_combination_id=cc.code_combination_idand cc.segment4 <> '00000'and cc.segment5 is not nullgroup by cc.segment4,cc.segment5 |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-11-04 : 07:10:43
|
You can use the same CASE expression as in splitting segment5 in expence and revenue.Just do the SUM() in the THEN part. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|