SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Expression problem displaying rolling weekly/daily/monthly average


Expression problem displaying rolling weekly/daily/monthly average

Author
Message
niccolem
niccolem
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 95
Hello:

I have a series of reports that I need to display a weekly,daily average of records that passed/failed validation. I can correctly bring in my record count from my stored procedure.
HOW can i correctly display via expression the weekly/daily/monthly average based on startdate parameter input.
Report need to look like:

Total Files Received

Avg Files Per Day

Avg Files Per Week

All reports are dynamic and only show months data is available.

Any help is greatly appreciated...
Dan.Humphries
Dan.Humphries
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5175 Visits: 1212
I would think you just need to break you date down into date parts and use that in you grouping.

So lets say you have a record set with the type of item being sold, the date of sale and amount.

to get daily average

select type, Ave(amount)
from sales
group by type,DATEPART( dd, SaleDate )

To get week average

select type, Ave(amount)
from sales
group by type,DATEPART( WK, SaleDate )

To get Month average
select type, Ave(amount)
from sales
group by type,DATEPART( mm, SaleDate )

I realize this is not a complete solution based on your request but it will hopefully point you in the right direction.

Dan

If only I could snap my figures and have all the correct indexes apear and the buffer clean and.... Start day dream here.
niccolem
niccolem
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 95
Thanks a lot, I figured it out by using first/last day of month
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (436K reputation)SSC Guru (436K reputation)SSC Guru (436K reputation)SSC Guru (436K reputation)SSC Guru (436K reputation)SSC Guru (436K reputation)SSC Guru (436K reputation)SSC Guru (436K reputation)

Group: General Forum Members
Points: 436296 Visits: 43509
niccolem (5/4/2010)
Thanks a lot, I figured it out by using first/last day of month


Are you passing those as a parameter? If so, what happens if someone forgets some like the fact that 2008 was a leap year and they type 28 Feb as the last day of the month? Or what if someone can't remember that months like August have 31 days and they type 30 Aug???

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search