date - SQL Defining Weeks From Days -
i'm trying summarize data in table weeks on past 10 months. field in table lists days in format dd-mm-yy. there simple way group these data weeks?
you try (tested sql server):
just paste code empty query window , execute. adapt needs.
declare @tbl table(datevalue varchar(8),othervalue int); insert @tbl values ('30-09-15',10) ,('29-09-15',20) ,('28-09-14',30) ,('28-08-14',10) ,('27-08-14',10); select convert(datetime,datevalue,3) converteddate ,datepart(wk,convert(datetime,datevalue,3)) weekindex ,othervalue @tbl --and way use aggregates ;with mydata ( select convert(datetime,datevalue,3) converteddate ,datepart(iso_week,convert(datetime,datevalue,3)) weekindex ,othervalue @tbl ) select weekindex,sum(othervalue) mydata group weekindex
Comments
Post a Comment