SELECT ( softl.softwarename ) "Software Name",
Max(workstation.workstationname) "Workstation",
Max(workstation.model) "Model",
Max(aaauser.first_name) "User",
Max(deptDef.deptname) "Department",
Max(workstation.loggeduser) "Last Logged In User",
Max(dominf.domainname) "Domain Name",
CASE
WHEN Max(Cast(compDefLaptop.islaptop AS VARCHAR(5))) = 1 THEN 'Laptop'
ELSE 'Desktop'
END "Desktop /Laptopn" FROM systeminfo workstation
LEFT JOIN resources resource
ON workstation.workstationid = resource.resourceid
LEFT JOIN componentdefinition product
ON resource.componentid = product.componentid
LEFT JOIN componentdefinitionlaptop compDefLaptop
ON product.componentid = compDefLaptop.componentid
LEFT JOIN resourceowner rOwner
ON resource.resourceid = rOwner.resourceid
LEFT JOIN resourceassociation rToAsset
ON rOwner.resourceownerid = rToAsset.resourceownerid
LEFT JOIN sduser sdUser
ON rOwner.userid = sduser.userid
LEFT JOIN aaauser aaaUser
ON sduser.userid = aaauser.user_id
LEFT JOIN departmentdefinition deptDef
ON rOwner.deptid = deptDef.deptid
LEFT JOIN systeminfodomain sysInfod
ON workstation.workstationid = sysInfod.workstationid
LEFT JOIN domaininfo dominf
ON sysInfod.domainid = dominf.domainid
LEFT JOIN softwareinfo swi
ON workstation.workstationid = swi.workstationid
LEFT JOIN softwarelist softl
ON swi.softwareid = softl.softwareid
WHERE softl.softwarename LIKE '%MICROSOFT%'
GROUP BY workstation.workstationid,
softl.softwarename