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
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.
Can I use some kind of Case statement in the Where field?
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