Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1073197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:57:44+00:00 2026-05-16T20:57:44+00:00

I have the following tables: users – userid – real name – other stuff

  • 0

I have the following tables:

users
 - userid
 - real name
 - other stuff

roles
 - roleid
 - description
 - other stuff

functions
 - functionid
 - description

screens
 - screenid
 - description

A user can have multiple roles, as controlled by the table

user_roles
 - userid
 - roleid

Each role can have either edit, view or no access to a given function as controlled by the table

role_functions
- roleid
- functionid
- status

status is ‘E’ if the role has edit permission on that function, ‘V’ if the role has view permission on that function, and there can either be no record, or one with a ‘N’ status if the role has no permission on that function.

Lastly a function has multiple screens, as controlled by the table

function_screens
 - functionid
 - screenid

It’s kind of a confusing mess, I know, but the requirements for the roles, functions, and screens come from different business units so I can’t simplify it. However, what I need is a query that I can give to the QA department and others that given a userid, they can list all the screens, and whether they have Edit, View or No access to that screen. If that user belongs to one role that gives them ‘E’ permission to a function that includes a screen, and another role that gives them ‘V’ permission to a function that includes the same screen, then their permission to that screen is ‘E’.

Right now I’m accomplishing all these lookups using a bunch of Java code with Maps of Maps, but I’m wondering if there is a simpler way to do it in a SQL script.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:57:44+00:00Added an answer on May 16, 2026 at 8:57 pm

    Try this:

    select s.screenid, s.description
    , CASE MAX(CASE rf.status WHEN 'E' THEN 2 WHEN 'V' THEN 1 ELSE 0 END)
        WHEN 2 THEN 'E'
        WHEN 1 THEN 'V'
        ELSE 'N' END as status
    from user_roles ur
    join role_functions rf on rf.roleid = ur.roleid
    join function_screens fs on fs.functionid = rf.functionid
    join screens s on s.screenid = fs.screenid
    where ur.userid = :theuser
    group by s.screenid, s.description
    order by s.screenid
    

    The 2 nested cases convert E, V and N to 2, 1 and 0 and back so that MAX can be used to get the “highest” status.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following tables in MySQL: team: id, name, [more stuff] person: id,
I have following situation. A main table and many other tables linked together with
I have the following code: ListBox.DataSource = DataSet.Tables(table_name).Select(some_criteria = match) ListBox.DisplayMember = name The
I have the following tables: USERS table id username email password status FRIENDS table
I have the following tables: create table Users( Id uniqueidentifier primary key, InfoId uniqueidentifier
i have the following db structure: Users: - UserID - UserName - FirstName -
I have the following tables in my database that have a many-to-many relationship, which
I have the following five tables: ISP Product Connection AddOn AddOn/Product (pivot table for
I have two tables with the following columns: table1: id, agent_name, ticket_id, category, date_logged
I have 2 tables with the following structure.. category { sub_cat_id - numeric sub_cat_name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.