For full details please see https://www.myitforum.com/Forums/tm.aspx?m=230539&high=

SELECT DISTINCT 
	R.Netbios_Name0, 
	tu.SystemConsoleUser0, 
	tu.logontime
FROM 
	dbo.v_R_System R
	join (
		SELECT 
			husr.ResourceID,
			Husr.SystemConsoleUser0, 
			max(Husr.LastConsoleUse0) as logontime
		FROM 
			dbo.v_HS_SYSTEM_CONSOLE_USER Husr 
		WHERE 
			Husr.SystemConsoleUser0 LIKE 'Gartek\' + @variable 
		Group by 
			husr.ResourceID,
			Husr.SystemConsoleUser0 
	) tu on tu.resourceID = R.resourceID
WHERE 
	tu.SystemConsoleUser0 LIKE 'Gartek\' + @variable 
ORDER BY 
	R.Netbios_Name0