What does this percent sign do ?

What does this SQL statement do and how does the % sign work
I am trying to get an averrage time per call and this is what I came across in the  exsisting code.

  ,RIGHT('00'+CAST((SUM(ACD.talkTime)/COUNT(ACD.StartDateTime)%60) AS VARCHAR),2) AS [Avg_Talk_Time]
rschmehlAsked:
Who is Participating?
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
modulo %, gives you the remainder of a division operation.

11 % 4 = 3, as it's two with three left over.
20 % 7 = 6, as it's two with six left over.

In the context of the T-SQL you posted, it looks like it's trying to just get the minute portion of ACD.StartDateTime.
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>CAST((SUM(ACD.talkTime)/COUNT(ACD.StartDateTime)%60)
Also looks like the parentheses marks are not correct, perhaps this should be..
RIGHT('00'+ CAST((SUM(ACD.talkTime)/COUNT(ACD.StartDateTime)) %60 AS VARCHAR(2)),2) AS [Avg_Talk_Time] 

Open in new window

0
 
rschmehlAuthor Commented:
Yes the %b acts like a MOD giving the remander.  I did not know it did this with TIME values but i guess it does.   Thanks
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
0
 
PortletPaulfreelancerCommented:
>> did not know it did this with TIME values
it isn't dealing with time units directly, in this case it is:  sum()/count() then modulus of 60

SUM(ACD.talkTime)/COUNT(ACD.StartDateTime) % 60

tip: modulus of 7 when working with days of week is excellent, e.g.

SELECT datediff(DAY,0,getdate()) % 7 -- 0 is Monday (regardless of sqlserver settings)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.