Вопрос

I recently encountered a requirement which said "Manager should see all record but Associates only appropriate subset. I will explain my requirement with below example.

I have a table.

CREATE TABLE [dbo].[Empolyee](
    [EmpID] [int] NOT NULL,
    [Name] [nvarchar](50) NOT NULL,
    [Salary] [int] NULL,
    [Grade] [char](1) NULL
)   

and some data

insert into Empolyee values(1, 'John', 200, 'C')

insert into Empolyee values(2, 'Jim', 100, 'D')

insert into Empolyee values(3, 'Jane', 500, 'A')

insert into Empolyee values(4, 'Jack', 150, 'C')

insert into Empolyee values(5, 'Jil', 300, 'B')

insert into Empolyee values(6, 'Josh', 350, 'B')

A is the highest grade, D is lowest.

I want to employee detail report in SSRS

simply showing

select * from Empolyee.

Now the requirement is user should be able to see his/her record and people at lower Grade.

E.g. If Jane see report she see should see all 6. If Jack see report she see should see only 2(his and Jim's)

I could see this is case of role based security but how to implement this?

Это было полезно?

Решение

Select B.[Name] AS [Name2],B.[Salary] AS [Salary2],B.[Grade] AS [Grade2] 
from Empolyee A
Cross jOIN Empolyee B
WHERE A.Grade <= B.Grade
and A.Name like 'Jack' -- mention your user here
AND B.EmpID NOT IN (Select EmpID FROM Empolyee C 
 WHERE C.Grade = A.Grade and C.Name <> A.Name)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top