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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Data DudeCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim HornMicrosoft SQL Server Data DudeCommented:
>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

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
Jim HornMicrosoft SQL Server Data DudeCommented:
Thanks for the grade.  Good luck with your project.  -Jim
PortletPaulEE Topic AdvisorCommented:
>> 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)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SSRS

From novice to tech pro — start learning today.