I want to get the result of these three queries dynamically into three separate columns respectively.
SELECT SUM(fee_amt) as Total_Fee from FEEDTL where Semester_No='2015SM' AND Registration_No='2015-1234' AND Fee_type='TUITION FEE'
SELECT SUM(fee_amt) as Balance from FEEDTL where Semester_no='2015SM' AND Registration_No='2015-1235' AND Fee_type='TUITION FEE' and Verify='No'
SELECT SUM(fee_amt) as Paid_Amt from FEEDTL where Semester_no='2015SM' AND Registration_No='2015-1236' AND Fee_type='TUITION FEE' and Verify='Yes'
You could merge these queries into a single query. The common conditions can stay in the where clause, and the non-common conditions can move to a
case
expression inside their respectivesum
s:Note that a
case
expression returnsnull
by default (i.e., when non of thewhen
orelse
clauses are matched, and thatsum
just ignoresnull
s.