SELECT au.FIRST_NAME "Technician",(ar.NAME) "Role",al.name "Login Name",ac.emailid "Email ID",
case when max(ts.status)='1' then 'True' else 'false' end "Current online Status" FROM Portaltechnicians hdcLEFT JOIN SDUser sd ON hdc.userid=sd.USERID
LEFT JOIN AaaLogin al ON sd.USERID=al.USER_ID
LEFT JOIN AaaUser au ON al.USER_ID=au.USER_ID
LEFT JOIN AaaAccount aa ON al.LOGIN_ID=aa.LOGIN_ID
left join aaausercontactinfo auc on au.user_id=auc.user_id
left join aaacontactinfo ac on auc.contactinfo_id=ac.contactinfo_id
LEFT JOIN SDAuthorizedRole aar ON aa.ACCOUNT_ID=aar.ACCOUNT_ID
LEFT JOIN AaaRole ar ON aar.ROLE_ID=ar.ROLE_ID
LEFT JOIN AaaRoleToCategory ON ar.ROLE_ID=AaaRoleToCategory.ROLE_ID
left join portalusers pu on sd.userid=pu.userid
left join technicianstatus ts on au.user_id=ts.technicianid
WHERE (ar.NAME NOT LIKE 'SDApprovePO') AND (AaaRoleToCategory.ROLE_ID IS NULL) and sd.status='ACTIVE'
and pu.status='ACTIVE'
and hdc.id is not nullgroup by au.FIRST_NAME,ar.NAME,al.name,ac.emailid ORDER BY au.FIRST_NAME