I have 3 tables in an SQL Server 2008 database. The first table contains users names, the second contains privileges and the last links the first two tables:
USERS (ID
integer, NAME
varchar(20));
PRIVS (ID
integer, NAME
varchar(50));
USERS_PRIVS (USERID
integer, PRIVID
integer);
For example, the USERS table has the following:
1, Adam
2, Benjamin
3, Chris
The PRIVS table has:
1, Add Invoice
2, Edit Invoice
3, Delete Invoice
The USERS_PRIVS table has:
1, 1
1, 2
1, 3
2, 1
2, 2
3, 1
I am looking for a way to create an SQL query that would return something like the following:
Add Invoice Edit Invoice Delete Invoice
Adam Y Y Y
Benjamin Y Y N
Chris Y N N
Is this possible using the pivot function?