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
 SQL SELECT AVG question

Author  Topic 

keithroby
Starting Member

6 Posts

Posted - 2008-11-19 : 08:26:25
I have a table full of course dates, instructors, courses and a series of 'scores' for a range of likert responses (1-5).

Ultimately I'm going to pass this view to a SQLDataSource in asp.net, but what would the view be on the Server side?

I want to be able to perform an AVG function off a user-inputted date range, where if the user selected 2/1/2008 as a start date and 6/1/2008 as an end date, the return would be avg scores for all the records in between (or inclusive of those dates).

Any input?

Thanks!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-19 : 08:30:50
something like

SELECT AVG(YourField)
FROM Yourtable
WHERE datefield BETWEEN @StartDate AND DATEADD(dd,1,@Enddate)
...
Go to Top of Page

keithroby
Starting Member

6 Posts

Posted - 2008-11-19 : 12:24:04
Thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-19 : 12:26:53
welcome
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-20 : 01:56:40
For accuracy, you may need to use
SELECT AVG(YourField*1.0)
FROM Yourtable
WHERE datefield BETWEEN @StartDate AND DATEADD(dd,1,@Enddate)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -