Here is a sample of the code I'm writing
DECLARE @totlunch int = 0;
DECLARE @totbreak int = 0;
DECLARE @over int = 0;
SELECT @totlunch = SUM(CASE when [StatusKey] = 'at lunch' then StateDuration else 0 end),
@totbreak = SUM(CASE when [StatusKey] = 'break' then StateDuration else 0 end)
FROM [I3_IC].[dbo].[AgentActivityLog]
WHERE UserId in ('mdavila')
AND StatusDateTime between '2014-08-28 00:00:00' AND '2014-08-28 23:59:59'
--group by UserId
print @totlunch;
print @totbreak;
if(@totlunch > 3600)BEGIN
SET @over = @over + (@totlunch - 3600);
END
if(@totbreak > 1800)BEGIN
SET @over = @over + (@totbreak - 1800);
END
print @over;
I want to do this task for a group of "UserId"s, insterad of juat "mdavila" but I'm not sure how to loop it as SQL queries seem to not support arrays. Any help in how I can accomplish this task would be greatly appreciated. Thanks!
Please note that I need to keep track of each user individually. I will populate a temp table with the data I want, but I just need to know a way of looping this code for a group of users.