Actually i am facing problem in joining of two tables and getting the right information for example i am having two tables(Fee_Quotation,Paid_Details)
table 1
//Fee_Quotation table(while admission student will commit for this amount.here below there is one student fee_quotation details 1001)
Student_ID|Fee_Type |Fee_Amount|Payment_Type |Commited_on
1001 |Registration_fee |100 |Annualy |2013-mar-8
1001 |Tution_fee |1000 |Monthly |2013-mar-8
1001 |Books |1000 |Annualy |2013-mar-8
table 2
//Paid_details table(here student will pay fee according to month)
Student_ID|Fee_Type |Fee_Amount|Payment_Type |Month |Paid_on
1001 |Registration_fee |100 |Annualy |mar |2013-mar-11
1001 |Tution_fee |500 |Monthly |mar |2013-mar-12
1001 |Tution_fee |500 |Monthly |mar |2013-mar-13
1001 |Books |500 |Annualy |mar |2013-mar-11
1001 |Books |300 |Annualy |mar |2013-mar-12
1001 |Tution_fee |500 |Monthly |apr |2013-apr-12
1001 |Tution_fee |400 |Monthly |apr |2013-apr-13
now i will pass three parameters like Student_ID=@Student_ID,Payment_type=@Payment_Type,Month=@Month
ex:- Student_ID=1001,Payment_Type='Monthly',Month='apr'
then i want the table like below
Student_ID|Fee_Type |Fee_Amount|LastMoDue|CurrentMoDue|TotalDue
1001 |Tution_Fee |1000 |0.00 |100 |100
if i will pass two parameters like
Student_ID=@Student_ID,Payment_type=@Payment_Type
ex:- Student_ID=1001,Payment_Type='Annualy'
then i want the table like below
Student_ID|Fee_Type |Fee_Amount|LastMoDue|CurrentMoDue|TotalDue
1001 |Regist_Fee |100 |0.00 |100 |100
1001 |Books |1000 |0.00 |1000 |1000
//this type of table we can get ha sir....i mean it is possible ha sir
[MOVED] from comment [/MOVED]
select q.Student_ID,q.Fee_Type,q.amount,q.amount-p.paid as Current_month_due,q.amount-g.paid as previous_month_due,(q.amount-g.paid)+(q.amount-p.paid) as total_amount from Student_Fee_Quotations q join (select d.Student_ID,d.Fee_Type,sum(d.amount) as paid
from FeePaid_Details d
where d.Student_ID='PS20130001' and d.Fee_Type='Admission Fee' and d.Month_Details='jan' group by d.Student_ID,d.Fee_Type )as g on q.Student_ID='PS20130001' and q.Fee_Type='Admission Fee' join (select d.Student_ID,d.Fee_Type,sum(d.amount) as paid from FeePaid_Details d where d.Student_ID='PS20130001' and d.Fee_Type='Admission Fee' and d.Month_Details='feb' group by d.Student_ID,d.Fee_Type ) as p on q.Student_ID='PS20130001' and q.Fee_Type='Admission Fee'