Page 1 of 1

Select all records if the logged in user is a global admin or only user records if not a globaladmin

Posted: Thu Jan 25, 2024 5:51 pm
by TitanCompMan
I'm using this SQL code in Browse for an Inventories form. How do I modify it to show all inventories if the logged in user is a global admin? Right now this just code just shows the records where the userid matches the logged in user.

Code: Select all

SELECT inventories.userid,
       inventories.inv_site,
       inventories.invroomid,
       inventories.yearsid,
       inventories.gradesid,
       zzzzsys_user.zzzzsys_user_id,
       sites.sites_id,
       rooms.roomsid,
       schoolyears.yearsid,
       grades.*
FROM inventories
JOIN zzzzsys_user ON inventories.userid = zzzzsys_user.zzzzsys_user_id
JOIN sites ON inventories.inv_site = sites.sites_id
JOIN rooms ON rooms.roomsid = inventories.invroomid
JOIN schoolyears ON inventories.yearsid = schoolyears.yearsid
JOIN grades ON inventories.gradesid = grades.grades_id
WHERE inventories.userid = '#USER_ID#'

Can I use some kind of Case statement in the Where field?

Code: Select all

WHERE 
    CASE 
        WHEN ????  = 'globaladmin' THEN ?????  -- Select all records for globaladmin
        ELSE inventories.userid = '#USER_ID#'  -- Select records for a specific user
    END

Re: Select all records if the logged in user is a global admin or only user records if not a globaladmin

Posted: Thu Jan 25, 2024 5:54 pm
by kev1n
Hi,

Try:

Code: Select all

WHERE inventories.userid = '#USER_ID#' OR '#GLOBAL_ACCESS#' = '1'

Re: Select all records if the logged in user is a global admin or only user records if not a globaladmin

Posted: Fri Jan 26, 2024 2:20 pm
by TitanCompMan
kev1n wrote: Thu Jan 25, 2024 5:54 pm Hi,

Try:

Code: Select all

WHERE inventories.userid = '#USER_ID#' OR '#GLOBAL_ACCESS#' = '1'
That worked!!!