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
 Query help

Author  Topic 

drpkrupa
Yak Posting Veteran

74 Posts

Posted - 2007-03-01 : 15:27:56
I have a table with two columne. Customerid and start_date.
I want a see all customerid by week.

Ex.

Id Start_date
1 1/5/2007
2 1/6/2007
3 1/25/2007
4 1/22/2007
5 2/19/2007
6 12/19/2006
7 12/22/2006

I need result like this.

Week Total
51/2006 2
1/2007 2
4/2007 2
8/2007 1

Then i need another query which give me detail by clicking the week.
Means if user click on 51/2006 then the want see detail of those two record.
like----- select customerid,start_date from customer where ?????
???? -- date range between week 51 or 2006.
and same think for other week data.

Thanks,


snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-03-01 : 15:34:24
Something like these queries

select datepart(ww, start_date) as [Week], year(start_date) as [Year], count(*) as [Count]
from yourtable
group by year(start_date), datepart(ww, start_date)
order by year(start_date), datepart(ww, start_date)


select * from yourtable
where year(start_date) = 2006 and datepart(ww, start_date) = 52

Go to Top of Page
   

- Advertisement -