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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 average for sql query for datediff function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ahmedpower
Starting Member

Qatar
6 Posts

Posted - 12/11/2012 :  06:45:34  Show Profile  Reply with Quote
Dear Team

Please support me to get the average for below sql query for datediff function.

SELECT a.[ticket_id]
,a.[created_on]
,a.[created_by]
,b.[done_by]
,b.[status_changed_to]
,b.[update_time]
,dbo.CastTime(datediff(s,a.created_on,b.update_time)) "Time Ticket"
FROM [ticket] a (nolock)
INNER JOIN [ticket_history] b (nolock)
ON a.ticket_id = b.ticket_id
where (datepart(mm,a.created_on)>=4 and datepart(mm,b.update_time)<=4)
and (datepart(yyyy,a.created_on)=2012 and datepart(yyyy,b.update_time)=2012)
and status_changed_to ='Close'
ORDER BY a.created_on


I really tired to do it unless I get the "Time Ticket"
but i need plus the average of total Time in sperate field

Ahmed Soliman

slimt_slimt
Aged Yak Warrior

Switzerland
746 Posts

Posted - 12/11/2012 :  14:54:16  Show Profile  Reply with Quote
Ahmed,

I see you are using dbo.castTime function. Unfortunately, I can not tell what this function does.

here is the average as I see it:

	SELECT 
			 a.[ticket_id]
			,a.[created_on]
			,a.[created_by]
			,b.[done_by]
			,b.[status_changed_to]
			,b.[update_time]
			--,dbo.CastTime(datediff(s,a.created_on,b.update_time)) as Time_Ticket
			,datediff(minute, a.create_on, b.update_time) as time_ticket
		FROM [ticket] a (nolock)
		INNER JOIN [ticket_history] b (nolock)
		ON a.ticket_id = b.ticket_id
		where 
			(datepart(mm,a.created_on)>=4 
		 and datepart(mm,b.update_time)<=4)
		 and (datepart(yyyy,a.created_on)=2012 
		 and datepart(yyyy,b.update_time)=2012)
		 and status_changed_to ='Close'
		 ORDER BY a.created_on
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.09 seconds. Powered By: Snitz Forums 2000