What you are looking for is called a cross-tab or pivot table query. Unfortunately, SQL Server does not have a simple way to handle this sort of thing. In this (one thing, IMO) Access has an advantage, as it provides a syntax to accomplish this in a more or less straightforward manner.
However, you can accomplish this in SQL Server using the CASE expression, as long as you know ahead of time how many columns will be involved.
Since you have 8 Sysid's, you do. Now it's just a matter of combining 8 CASE expressions (one for each system) as:
Code:
SELECT UserLogin,
SUM(CASE WHEN SysId=1 THEN 1 ELSE 0 END) as '1'
SUM(CASE WHEN SysId=2 THEN 1 ELSE 0 END) as '2'
SUM(CASE WHEN SysId=3 THEN 1 ELSE 0 END) as '3'
SUM(CASE WHEN SysId=4 THEN 1 ELSE 0 END) as '4'
SUM(CASE WHEN SysId=5 THEN 1 ELSE 0 END) as '5'
SUM(CASE WHEN SysId=6 THEN 1 ELSE 0 END) as '6'
SUM(CASE WHEN SysId=7 THEN 1 ELSE 0 END) as '7'
SUM(CASE WHEN SysId=8 THEN 1 ELSE 0 END) as '8'
FROM YourTable
GROUP BY UserLogin
ORDER BY UserLogin;
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com