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
 Date string - select and group by week

Author  Topic 

Stan1978
Starting Member

31 Posts

Posted - 2011-07-26 : 11:08:02
I have a column in the table which represents a date 02/20/2011 and a trans id e.g.

'2011021600000000000'

I want group by week.

e.g. I choose a start date Monday 4th July and then sum my transactional data by week 1, week 2, week 3 etc.

Sorry if the confusion is slightly muddled thank you for reading and any help!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-07-26 : 11:26:01
[code]SELECT DATEPART(wk,CONVERT(datetime,LEFT(field,8),112)) ,SUM(Sales) AS TotalSales
FROM Table
GROUP BY DATEPART(wk,CONVERT(datetime,LEFT(field,8),112))
[/code]

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

Go to Top of Page

Stan1978
Starting Member

31 Posts

Posted - 2011-07-26 : 11:38:46
Looks good thanks a lot.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-07-26 : 11:45:20
welcome

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

Go to Top of Page
   

- Advertisement -