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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Aggregate Function Problem! please help

Author  Topic 

Yonkouturko
Yak Posting Veteran

59 Posts

Posted - 2013-02-01 : 05:42:42
SELECT SUM(Table_NEWDR_Payment_History.Amount_Received) AS [Total Amount Received], Table_NEW_DR.ReferenceNumber
FROM Table_NEW_DR INNER JOIN
Table_NEWDR_Payment_History ON Table_NEW_DR.ReferenceNumber = Table_NEWDR_Payment_History.ReferenceNumber

GROUP BY Table_NEW_DR.ReferenceNumber, Table_NEWDR_Payment_History.ReferenceNumber

i have REFERENCENUMBER AS ID here
now i have records from 0000000001 to 0000000023

but the records below didn't show ReferenceNumbers

0000000008,0000000009,0000000010,0000000011

50500 0000000001
1207500 0000000002
580 0000000003
500 0000000004
5500 0000000005
2600 0000000006
10000 0000000007
NULL 0000000012
3920 0000000013
4560 0000000014
13000 0000000015
1000 0000000017
12860 0000000018
200 0000000019
NULL 0000000020
NULL 0000000021
NULL 0000000022
250 0000000023


what will i do to show the records
0000000008,0000000009,0000000010,0000000011
please help...

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-01 : 06:36:40
may be they dont have any payment history. in that case, make it like


SELECT SUM(Table_NEWDR_Payment_History.Amount_Received) AS [Total Amount Received], Table_NEW_DR.ReferenceNumber
FROM Table_NEW_DR LEFT JOIN
Table_NEWDR_Payment_History ON Table_NEW_DR.ReferenceNumber = Table_NEWDR_Payment_History.ReferenceNumber

GROUP BY Table_NEW_DR.ReferenceNumber, Table_NEWDR_Payment_History.ReferenceNumber


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Yonkouturko
Yak Posting Veteran

59 Posts

Posted - 2013-02-02 : 06:24:11
Ohh shucks... I've Tried LEft join earlier but it did not work... i wonder why...
but your's works!!! THANK YOU SO MUCH MY FRIEND!!!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-02 : 07:59:01
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -