Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Kalaiselvan
Posting Yak Master

India
112 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
52326 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  
 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