Script Help

  • We have a table that stores the user permissions to specific programs, USER_PGM_AUTHORITY. The table holds two items either R (Read-only) or N (No Access). If neither of these are in the table then the user has write access. We are trying to build a script that will list all users who have write access to a specific program (INV_OPT). This is challenging due to the fact that there is not a placeholder in the table when a user has write access. Any ideas how we can accomplish this?

  • Select * from USER_PGM_AUTHORITY where ACCESS is null and Program = 'INV_OPT'

    If you can post the table and some sample data I can answer your question more specifically.

  • admin is on the right track;

    i think you might need to start with a base table of all users, then join it to this table to generate your list;

    something like:

    Select USERNAME,* FROM

    MASTERLISTOFUSERS

    LEFT OUTER JOIN USER_PGM_AUTHORITY

    ON MASTERLISTOFUSERS.USERID = USER_PGM_AUTHORITY.USERID

    where USER_PGM_AUTHORITY.ACCESS is null and USER_PGM_AUTHORITY.Program = 'INV_OPT'

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • If a user has permission to a program there is not a null value. There is no placeholder whatsoever. So, I can not use "permission is null" in a script. Here is the table layout:

    [dbo].[USER_PGM_AUTHORITY](

    [ROWID] [int] IDENTITY(1,1) NOT NULL,

    [USER_ID] [varchar](20) NOT NULL,

    [PROGRAM_ID] [varchar](8) NOT NULL,

    [PROGRAM_COMPONENT] [varchar](8) NOT NULL,

    [PERMISSION] [char](1) NOT NULL DEFAULT (''),

    [PROFILE_STRING] [varchar](80) NULL,

    CONSTRAINT [PK_USER_PGM_AUTHORITY] PRIMARY KEY CLUSTERED

  • bpowers (9/21/2009)


    If a user has permission to a program there is not a null value. There is no placeholder whatsoever. So, I can not use "permission is null" in a script. Here is the table layout:

    yes exactly, so your biz rule is "everyone has access UNLESS there is an entry in this table"

    that's why you have to start with a master list of users, and join for "permission is null" ; really

    WHERE [PERMISSION] IS NULL or [PERMISSION] ='' ,

    either way, that field would be null if there is no row in the table when using a left outer join.

    does that help?

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Here is the script I built on your suggestion. It returns no records.

    SELECT DISTINCT NAME

    FROM APPLICATION_USER

    LEFT JOIN USER_PGM_AUTHORITY ON APPLICATION_USER.NAME = USER_PGM_AUTHORITY.USER_ID

    WHERE PERMISSION IS NULL AND PROGRAM_ID = 'VMINVENT'

  • ahh... the WHERE statements are turning the left outer join into an inner join.

    try this instead:

    SELECT DISTINCT NAME

    FROM APPLICATION_USER

    LEFT JOIN USER_PGM_AUTHORITY

    ON APPLICATION_USER.NAME = USER_PGM_AUTHORITY.USER_ID

    AND USER_PGM_AUTHORITY.PROGRAM_ID = 'VMINVENT'

    WHERE USER_PGM_AUTHORITY.PERMISSION IS NULL

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Tried flip flopping the tables but it still does not return any records. I believe it is due to the fact that I am testing for a program id of "VMINVENT". This too will not be stored in the table if a user has write acces. Something that seems so simple has been a pain to get to.

    SELECT DISTINCT USER_ID

    FROM USER_PGM_AUTHORITY

    LEFT JOIN APPLICATION_USER ON USER_PGM_AUTHORITY.USER_ID = APPLICATION_USER.NAME

    WHERE PERMISSION IS NULL AND PROGRAM_ID = 'VMINVENT'

  • That worked! How was it getting turned into an inner join?

  • Is what you did. Thanks a million for the help. It is greatly appreciated.

  • it's one of those "GOTCHAS" with the left outer join;

    a left outer join should test for a column=null or not null on the joined table;

    if it tests for anything else on the joined table in the WHERE statement, it changes it to an inner join..

    AND PROGRAM_ID = 'VMINVENT' was what killed us in our first version:

    it basically took the result set you would have seen, a list of names, and joined NULL = 'VMINVENT', which killed our result set.

    hope that helps!

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks for the lesson. It is appreciated.

Viewing 12 posts - 1 through 11 (of 11 total)

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