RSS Forums RSS
Please support our MS SQL advertiser: Programming Forums

query for creating report group by weeks (with start date and end date of the week)

Join Date: Feb 2007
Location: London
Posts: 114
Reputation: davidcairns is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
davidcairns davidcairns is offline Offline
Junior Poster

Re: query for creating report group by weeks (with start date and end date of the wee

  #6  
Apr 23rd, 2007
First things first then

Change this to allow any indexes to be used. Always do the convert on the scalar data if possible
CONVERT(char(10),formreceiveddate, 103) <> '01/01/1900'
to
formreceiveddate <> CONVERT(datetime,'01/01/1900',103)

Secondly, this will be much neater if you just dump out the data grouped by the sales rep and week and use Excel or ASP to diplay it the way you want. Hence the query will be

SELECT pmr.pmrname, (datepart(cor.formreceiveddate) - 1) / 7 + 1 as [week], count(p.patientid) as [Patients]
FROM
doctor d,
clinic c,
pmr pmr,
patient p,
course cor
WHERE
d.clinicid=c.clinicid
AND
c.pmrid=pmr.pmrid
AND
pmrname='Bruce Tham'
AND
d.doctorid=p.doctorid
AND
cor.patientid=p.patientid
AND
formreceiveddate <> CONVERT(datetime,'01/01/1900',103)
GROUP BY pmr.pmrname, (datepart(cor.formreceiveddate) - 1) / 7 + 1
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:24 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC