Last active
June 16, 2022 04:36
-
-
Save Eun/942e02fc909483b94584cf510eb656da to your computer and use it in GitHub Desktop.
Get Skype for Business Status via SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT LOWER(UserAtHost) AS UserAtHost, Status= | |
CASE | |
WHEN Availability BETWEEN 0 AND 2999 THEN Availability | |
WHEN Availability BETWEEN 3000 AND 4499 THEN 'Available' | |
WHEN Availability BETWEEN 4500 and 5999 THEN 'Available - Idle' | |
WHEN Availability BETWEEN 6000 and 7499 THEN 'Busy' | |
WHEN Availability BETWEEN 7500 and 8999 THEN 'Busy - Idle' | |
WHEN Availability BETWEEN 9000 and 11999 THEN 'Do not Disturb' | |
WHEN Availability BETWEEN 12000 and 14999 THEN 'Be right back' | |
WHEN Availability BETWEEN 15000 and 17999 THEN 'Away' | |
WHEN Availability >= 18000 THEN 'Offline' | |
END, | |
LastPubTime | |
FROM rtc.dbo.Resource Resource | |
RIGHT JOIN ( | |
SELECT | |
Instance.PublisherId, | |
SUBSTRING(Instance.Data, CHARINDEX('<availability>', Instance.Data) + 14, CHARINDEX('</availability>', Instance.Data) - CHARINDEX('<availability>', Instance.Data) - 14) AS Availability, | |
Instance.LastPubTime | |
FROM ( | |
SELECT PublisherId, cast(substring(Data, 0, 256) AS varchar(256)) AS Data, LastPubTime FROM rtcdyn.dbo.PublishedInstance WHERE ContainerNum = 2 AND CategoryId = 4 | |
UNION ALL | |
SELECT PublisherId, cast(substring(Data, 0, 256) AS varchar(256)) AS Data, LastPubTime FROM rtc.dbo.PublishedStaticInstance WHERE ContainerNum = 2 AND CategoryId = 4 | |
) AS Instance | |
WHERE | |
CHARINDEX('aggregateState', Data) > 0 | |
) AS UserAndAvailability ON Resource.ResourceId = PublisherId | |
/*WHERE UserAtHost = '[email protected]' COLLATE SQL_Latin1_General_CP1_CI_AS*/ | |
ORDER BY UserAtHost, LastPubTime DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
Could you tell me how to group by states?
Thank you