Click here to Skip to main content
15,117,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I'm using two columns in Table T_T_VOUCHER...

VCR_VOUCHER_TYPE   VCR_AMOUNT
AIN                1000
AIN                2000
AIN                -1000
ACN                4000
ACN                5000
ACN                -2000



I want a procedure in which I want to display the two columns into three columns as given below

VCR_VOUCHER_TYPE    VCR_AMOUNT1    VCR_AMOUNT2
          AIN              2000            0
          ACN              0               7000            



I want to sum the amount separately for AIN and ACN in VCR_VOUCHER_TYPE and show it in two columns..Help me
Posted
Updated 1-Mar-12 21:45pm
v3
Comments
walterhevedeich 2-Mar-12 2:46am
   
Don't shout. Typing all in uppercase is considered shouting.
OriginalGriff 2-Mar-12 3:07am
   
We can't, based on that information.
It is not at all clear why you would add what into which total - we would need at least the logic behind it - I cannot see any scheme which gets your results from your inputs!
Use the "Improve question" widget to edit your question and provide better information.

1 solution

Is your number of columns fixed? Will your voucher type be always AIN and ACN alone. In that case try this query

SQL
Select data.VCR_VOUCHER_TYPE, case when (data.VCR_VOUCHER_TYPE = 'AIN') then data.amount else 0  end VCR_Amount1,
case when (data.VCR_VOUCHER_TYPE = 'ACN') then data.amount else 0 end  VCR_Amount2
from
(Select VCR_VOUCHER_TYPE, SUM(VCR_Amount) amount from T_T_voucher group by VCR_VOUCHER_TYPE) data
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900