Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Getting the average
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tkotey
Yak Posting Veteran

75 Posts

Posted - 02/23/2013 :  08:31:18  Show Profile  Reply with Quote
Hello

How do I sum and get average of rows from this statement

--
SELECT DateDiff(dd,convert(datetime,invRecDate,103),convert(datetime,invToAdminPrepDT,103))-DateDiff(ww,convert(datetime,invRecDate,103),convert(datetime,invToAdminPrepDT,103))*2 AS Days FROM reportViewHQ WHERE invWorkshop = 'Fleet'
--

Thanks for your help

Edited by - tkotey on 02/23/2013 08:34:18

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 02/23/2013 :  09:36:35  Show Profile  Reply with Quote
SELECT
	SUM(Days) AS SumofDays,
	AVG(1.0*Days) AS AvgofDays
FROM
(
	SELECT DateDiff(dd,convert(datetime,invRecDate,103),
		convert(datetime,invToAdminPrepDT,103))-DateDiff(ww,convert(datetime,invRecDate,103),
		convert(datetime,invToAdminPrepDT,103))*2 AS Days 
	FROM reportViewHQ 
	WHERE invWorkshop = 'Fleet'	
) s
Go to Top of Page

tkotey
Yak Posting Veteran

75 Posts

Posted - 02/23/2013 :  10:04:56  Show Profile  Reply with Quote
Thanks Jams K for help.

Edited by - tkotey on 02/23/2013 10:45:51
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000