SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Aggregate Function Problem! please help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yonkouturko
Yak Posting Veteran

Philippines
59 Posts

Posted - 02/01/2013 :  05:42:42  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 02/01/2013 :  06:36:40  Show Profile  Reply with Quote
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

Philippines
59 Posts

Posted - 02/02/2013 :  06:24:11  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 02/02/2013 :  07:59:01  Show Profile  Reply with Quote
welcome

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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000