I have data in a SQL Server 2016 table and I want output as shown below:
So basically I have all databases as column names (DYNAMIC - so the number of columns i.e. database names can increase/decrease) and in the user_name column, I have a list of all groups and members.
However, the group displays its permission level on a particular database column to which the group belongs.
I want to display only members of the group in the output along with its groupname and permission level on the database same as the group had.
Sample table script:
CREATE TABLE dbo.test
(
Sequence bigint identity(1,1) not null,
user_name nvarchar(100),
LoginType varchar(50),
[master] varchar(50),
[tempdb] varchar(50),
BI_SOPS varchar(50),
BI_PSO varchar(50),
BI_SUP varchar(50),
BI_FIN varchar(50),
BI_EDU varchar(50),
groupname nvarchar(100),
DBName varchar(50)
);
INSERT INTO dbo.test (user_name ,LoginType, master ,tempdb ,BI_SOPS ,BI_PSO ,BI_SUP ,BI_FIN,BI_EDU,groupname,DBName )
VALUES ('VINX\SqlServer_FIN','WINDOWS_GROUP',NULL,NULL,NULL,NULL,NULL,'db_datareader',NULL,NULL,NULL),
('TR\u1','WINDOWS_GROUP- User',NULL,NULL,NULL,NULL,NULL,NULL,NULL,'VINX\SqlServer_FIN','BI_FIN'),
('TR\u2','WINDOWS_GROUP- User',NULL,NULL,NULL,NULL,NULL,NULL,NULL,'VINX\SqlServer_FIN','BI_FIN');
SELECT * FROM dbo.test;
1条答案
按热度按时间ckocjqey1#
It's not clear what your problem is. Try this