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 2008 Forums
 Transact-SQL (2008)
 Outstanding Transaction Query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Kalaiselvan
Posting Yak Master

India
110 Posts

Posted - 08/21/2013 :  03:19:34  Show Profile  Reply with Quote
Hi,
I got a table with Transaction of Debit and Credit Amount. Need a Output for Current Outstanding Amount for Past 30 days Debited Data.

TableA:
[ID] [DATE] [DEBIT] [CREDIT] [NAME]
1 2013-06-01 500 - A
2 2013-06-15 750 - B
1 2013-06-30 - 400 A
2 2013-07-01 - 750 B
3 2013-07-20 200 - C
4 2013-07-25 500 - D
5 2013-07-30 300 - E
4 2013-08-01 - 300 D
3 2013-08-10 - 200 C
6 2013-08-15 400 - F
6 2013-08-15 - 300 F

From the Above Table Current Outstanding Will be SUM(DEBIT)-SUM(CREDIT) -- 2650-1950=700
But I need the Outstanding Pending Amount for Past Months Data which was not Credited.

OUTPUT: (Current Month Transaction of Debit will not Considered but have to Consider the Credit Amount For Past Transaction)
[ID] [DATE] [DEBIT] [CREDIT] [NAME]
1 2013-06-01 500 - A
2 2013-06-15 750 - B
1 2013-06-30 - 400 A
2 2013-07-01 - 750 B
3 2013-07-20 200 - C
4 2013-07-25 500 - D
5 2013-07-30 300 - E
4 2013-08-01 - 300 D
3 2013-08-10 - 200 C

Now the SUM(DEBIT)-SUM(CREDIT) -- 2250-1650=600.
Please help me to fix with Query...



Regards,
Kalai

VeeranjaneyuluAnnapureddy
Posting Yak Master

India
169 Posts

Posted - 09/03/2013 :  08:19:26  Show Profile  Reply with Quote
SELECT Value = (SUM(DEBIT) - SUM(CREDIT) )FROM TABLE

SELECT Value = (SUM(DEBIT) - SUM(CREDIT) )FROM TABLE1

veeranjaneyulu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 09/03/2013 :  09:36:45  Show Profile  Reply with Quote
can you explain how you managed exclude last two rows? you've previous two rows also coming for same month but you took that into consideration.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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.06 seconds. Powered By: Snitz Forums 2000