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 2005 Forums
 Transact-SQL (2005)
 get total amount by date

Author  Topic 

sign_seventh
Yak Posting Veteran

66 Posts

Posted - 2008-04-10 : 05:02:31
this is my sample records in my table


Sdate Amount
January 2007 250000.00
March 2007 300000.00
January 2008 350000.00



how can i get the amount from February to
May 2007 and sum it up like this


Details
February 2007 250000.00
March 2007 300000.00
April 2007 300000.00
May 2007 300000.00



this is all that i want to get
Total Amount: 1,150,000.00

i also posted this one in new to sql server section, but im hoping to get others opinion here. thnx

Shamee_1321
Starting Member

15 Posts

Posted - 2008-04-10 : 07:11:44
try this

SELECT SUM(AMOUNT)AS TOTALAMOUNT FROM TABLENAME
WHERE DATEPART(MONTH,SDATE) > 2
AND DATEPART(MONTH,SDATE) < 6
AND DATEPART(YEAR,SDATE)=2007
Go to Top of Page

sign_seventh
Yak Posting Veteran

66 Posts

Posted - 2008-04-10 : 07:35:42
this will only give me a sum of 300,000.00 i still need the amount for march,april,May. april and may amount will be base on the last month who have the amount. thats why the amount of april and may will be 300,000.00 like what i put in my details.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-10 : 07:44:26
Is this a continaution from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=100660 ?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

sign_seventh
Yak Posting Veteran

66 Posts

Posted - 2008-04-10 : 07:49:12
yes.. just hoping to get others opinion here. thnx
Go to Top of Page
   

- Advertisement -