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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 help require

Author  Topic 

my_my
Starting Member

2 Posts

Posted - 2010-11-04 : 06:53:16
I have a table whose columns are
Project_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.
Go to Top of Page

kvbc85
Starting Member

2 Posts

Posted - 2010-11-04 : 07:06:10
its require more descriptions
Go to Top of Page

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 cc
where bl.code_combination_id=cc.code_combination_id
and cc.segment4 <> '00000'
and cc.segment5 is not null
group by cc.segment4,cc.segment5
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -