MS SQL Query Sum of subquery
Posted
by
San
on Server Fault
See other posts from Server Fault
or by San
Published on 2011-01-31T04:59:56Z
Indexed on
2011/01/31
7:27 UTC
Read the original article
Hit count: 568
sql-server
|query
Hello ,
I need a help i getting following output from the query .
SELECT
ARG_CONSUMER,
cast(ARG_TOTALAMT as float)/100 AS 'Total',
(SELECT SUM(cast(DAMT as float))/100 FROM DEBT WHERE DDATE >= ARG.ARG_ORIGDATE AND DDATE <= ARG.ARG_LASTPAYDATE AND DTYPE IN ('CSH','CNTP','DDR','NBP') AND DCONSUMER = ARG.ARG_CONSUMER
) AS 'Paid'
FROM
ARGMASTER ARG
WHERE ARG_STATUS = '1'
Current output is a list of all records...
But what i want to achieve here is
count of arg consumers
Total of ARG_TOTALAMT
total of that subquery PAID
difference between PAID & Total amount.
I am able to achieve first two i.e. count of consumers & total of ARG _ TOTALAMT... but i am confused about sum of of ...i.e.
sum (SELECT SUM(cast(DAMT as float))/100 FROM DEBT WHERE DDATE >= ARG.ARG_ORIGDATE AND DDATE <= ARG.ARG_LASTPAYDATE AND DTYPE IN ('CSH','CNTP','DDR','NBP') AND DCONSUMER = ARG.ARG_CONSUMER) AS 'Paid'
Please advice
© Server Fault or respective owner