December 4, 2009 at 6:35 am
I need a procedure to split the month by weekly. It has to consider month 1st day is starting week.
in 1st week i have to get week1, in the second week i have to show week2 and so on...
Please help regarding this....
Thanks
December 4, 2009 at 7:16 am
Something like
select dateadd(month,datediff(month,0,date_col),0),
sum(case when date_col>=dateadd(month,datediff(month,0,date_col),0)
and date_col<dateadd(month,datediff(month,0,date_col),8) then 1 else 0 end) as first_week,
sum(case when date_col>=dateadd(month,datediff(month,0,date_col),8)
and date_col<dateadd(month,datediff(month,0,date_col),15) then 1 else 0 end) as second_week,
sum(case when date_col>=dateadd(month,datediff(month,0,date_col),15)
and date_col<dateadd(month,datediff(month,0,date_col),22) then 1 else 0 end) as third_week,
sum(case when date_col>=dateadd(month,datediff(month,0,date_col),22)
and date_col<dateadd(month,datediff(month,0,date_col),29) then 1 else 0 end) as fourth_week,
count(*) from your_table
group by dateadd(month,datediff(month,0,date_col),0)
Failing to plan is Planning to fail
December 4, 2009 at 7:26 am
It would help if provided the DDL (CREATE TABLE statements), sample data (in a readily consummable format that can be cut/paste/run in SSMS), expected results bassed on the sample data, and what you have done so far to solve your problem.
Need help with this? Please read the first article I have referenced below in by signature block.
Doing this will get you faster help and tested code in return.
December 4, 2009 at 7:55 am
i will give you an example...Let's take december month..I have to get 1st week in 1-5 and second week 6-12 and third week 13-19 fourth week 20-26 and fifth week 27-31
December 4, 2009 at 7:56 am
i will give you an example...Let's take december month..I have to get 1st week in 1-5 and second week 6-12 and third week 13-19 fourth week 20-26 and fifth week 27-31
December 4, 2009 at 8:00 am
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply