Want to create a view that shows data based on Microsoft domain login

  • Is there any way to create a view that can show records based on the Microsoft domain login?

    If I had a table with supervisors and a column with their domain login that would tie to results in another table (let's say employees that worked under them)....I want the view to only show the employees that work for them. But I can't seem to figure out what syntax to use to pass the domain login. Help!!!

  • You could use a stored proc and capture the calling user, as long as they are using windows login and then use the value in the proceding select

    declare @loginame nvarchar(250)

    set @loginame = (select top 1 loginame)

    from sys.sysprocesses where spid=@@spid)

    Andrew

  • Or create roles or logins that are windows security groups and use these to assign rights.

  • Hi

    If your users are connected via domain authentication you can use the sys.dm_exec_sessions. Have a look to the login_name column:

    SELECT * FROM sys.dm_exec_sessions WHERE session_id = @@SPID

    If not you can use a table valued function instead of a view.

    Greets

    Flo

  • n_parker (4/8/2009)


    Is there any way to create a view that can show records based on the Microsoft domain login?

    If you are using Windows Authentication, you can use SUSER_NAME()

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply