Link to home
Start Free TrialLog in
Avatar of rschmehl
rschmehlFlag for United States of America

asked on

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]
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>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

Avatar of rschmehl

ASKER

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
Thanks for the grade.  Good luck with your project.  -Jim
>> 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)