This can be run in SSMS but not Lansweeper reporting because of the temp table. It will give you the most frequent logon over 60 days. We later join it with asset info to pull expiring warranty by user and department for budgeting purposes.
-- First query: Get the most frequent logon user for each AssetID
WITH LogonCounts
AS (SELECT AssetID,
username,
COUNT(*) AS logon_count,
ROW_NUMBER() OVER (PARTITION BY AssetID ORDER BY COUNT(*) DESC) AS rn
FROM tblCPlogoninfo
WHERE logontime >= DATEADD(DAY, -60, GETDATE())
GROUP BY AssetID,
username)
SELECT AssetID,
username AS PrimaryLogin,
logon_count
INTO #tempLogonInfo
FROM LogonCounts
WHERE rn = 1
ORDER BY AssetID;