Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have a table with two columne. Customerid and start_date.I want a see all customerid by week.Ex.Id Start_date1 1/5/20072 1/6/20073 1/25/20074 1/22/20075 2/19/20076 12/19/20067 12/22/2006I need result like this.Week Total51/2006 21/2007 24/2007 28/2007 1Then 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 yourtablegroup by year(start_date), datepart(ww, start_date)order by year(start_date), datepart(ww, start_date)
select * from yourtablewhere year(start_date) = 2006 and datepart(ww, start_date) = 52