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
 General SQL Server Forums
 New to SQL Server Programming
 Select Sum Group By Month

Author  Topic 

Chris8080
Starting Member

2 Posts

Posted - 2009-06-06 : 11:20:28
Hi,

I've got an ODBC connection into an xls File. Within this file I've got:
CustomerID, CustomerNumber, PurchaseDate, CostsTotal
Now I want to retrieve some data:
1. Which Customer Purchased what? (is simple, I already got it)
2. Show me all the Orders with their costs AND the monthly CostsTotal.
In other words: What was my turnover during the months in total and what Customer purchased for which amount of money?

Can you please help me with this query?
Dateformat: 14.05.2009 00:00

%.05.% doesn't work, because this would only be 05, but I need all the months :(

Thank you in advance.
Bye, Chris

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-06 : 13:16:12
select datepart(year, purchasedate), datepart(month, purchasedate), sum(coststotal)
from table1
group by datepart(year, purchasedate),datepart(month, purchasedate)


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-07 : 03:44:04
quote:
Originally posted by Chris8080

Hi,

I've got an ODBC connection into an xls File. Within this file I've got:
CustomerID, CustomerNumber, PurchaseDate, CostsTotal
Now I want to retrieve some data:
1. Which Customer Purchased what? (is simple, I already got it)
2. Show me all the Orders with their costs AND the monthly CostsTotal.
In other words: What was my turnover during the months in total and what Customer purchased for which amount of money?

Can you please help me with this query?
Dateformat: 14.05.2009 00:00

%.05.% doesn't work, because this would only be 05, but I need all the months :(

Thank you in advance.
Bye, Chris


sorry didnt get you, are you asking for cummulative total or formatting of date value?
Go to Top of Page

Chris8080
Starting Member

2 Posts

Posted - 2009-06-08 : 10:17:38
Hi,

I want to display the sum or cummulative value.
But unfortunately, I can't use datepart with ODBC to an XLS.
I just get the error Syntax error in SQL expression.

Is there an alternative way to datepart?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-09 : 12:06:31
quote:
Originally posted by Chris8080

Hi,

I want to display the sum or cummulative value.
But unfortunately, I can't use datepart with ODBC to an XLS.
I just get the error Syntax error in SQL expression.

Is there an alternative way to datepart?


where are you writing this query? in excel?
Go to Top of Page
   

- Advertisement -