View Records That Are Associated With a User Table

  • I would like to find a way to setup a user table with logins (UserID) in one column and a department number in another column. A single user might be associated with multiple department numbers. When a report is run I would like the user to only see department data for the departments they are associated with in the table.

    The article below is close to what I need except that a user is only associated with ONE department. I will have some people that are over multiple departments and will need access to all of those.

  • I don't understand why you think the article you reference doesn't solve the problem. It certainly allows each user to be associated with (and therefor see data concerning) one or multiple offices, so the only change you appear to need is to change the word "office" to "department", ie it is purely a terminology difference.

    Tom

  • Thanks for the response! The example looks like it works for employees that would be associated with only one office. Mine will have multiple offices (departments). Am I missing something in the example?

  • Look at the example beginning with this text:

    the Report

    In order to test the report, login as a particular user or launch Internet Explorer by right clicking on it, selecting Run As, and entering the credentials to use. I have setup two accounts for my test: Tom has access to all offices and Joe is restricted to just seeing two offices.

    You'll see that when run by joe the report produces information for two offices, when run by tom it produces information for 6 offices.

    According to the article, the user-office association is defined in the table declared like this:

    CREATE TABLE [dbo].[UserOffice](

    [UserOfficeKey] [smallint] IDENTITY(1,1) NOT NULL,

    [UserAccount] [nvarchar](50) NOT NULL,

    [OfficeKey] [smallint] NOT NULL

    )

    ALTER TABLE dbo.UserOffice

    ADD CONSTRAINT pk_UserOffice

    PRIMARY KEY CLUSTERED (UserAccount, OfficeKey)

    This table allows multiple rows for each user since there's no unique constraint on the UserAccount column, so each user can be associated with multiple offices.

    Tom

  • Thank you for the clarification. I appreciate your help!

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

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