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
 Other SQL Server Topics (2005)
 Query

Author  Topic 

just.net
Starting Member

24 Posts

Posted - 2010-04-25 : 03:25:30
Hi,

i have table like this:

Time sum
16/05/2010 16:36 $2,323.00
16/06/2010 16:36 $4,232.00
16/07/2010 16:36 $444.00
16/08/2010 16:36 $32,444.00
16/09/2010 16:36 $4,422.00
16/05/2010 16:36 $2,323.00
16/07/2010 16:36 $444.00


i want to create a query that returns somthing like that:

month sum
5 $85,280.38
6 $888.00
7 $324,234.00
8 $34.00
9 $234.00
10 $23,423.00
11 $4,234.00
12 $234.00
1 $4,234.00
2 $234.00
3 $234.00
4 $234.00

it's result for the 12 months ahead from the current month.

thanks alot.


khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-04-25 : 03:34:40
what is the logic ? how do you get those numbers ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

just.net
Starting Member

24 Posts

Posted - 2010-04-25 : 04:33:52
it's should be the SUM of the revenue in each month,
these numbers are just random numbers....
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-04-25 : 04:36:03
[code]
select datepart(month, [Date]), sum(amount)
from yourtable
group by datepart(month, [Date])
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-25 : 05:03:37
if you've data for more than year then

select datepart(year, [Date]),datepart(month, [Date]), sum(amount)
from yourtable
group by datepart(year, [Date]),datepart(month, [Date])


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

Go to Top of Page

just.net
Starting Member

24 Posts

Posted - 2010-04-25 : 06:26:59
Thank you all,
so simple, but yet - so sophisticated.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-25 : 11:05:31
welcome

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

Go to Top of Page
   

- Advertisement -