Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

What us the best way to accomplish this?

$
0
0

Hello, I have the following 6 tables

Districts - contains the district id and district name

District_access - used to identify which districts a user has access to

operation_centers - contains the ops center id and name

ops_access - used to identify which ops centers a user has access to

projects- contains project id and name

project_access - used to idenify which projects a user has access to

I'm currently using this query and it returns the districts,ops centers and projects a user has access to. The problem is that if a user has access to district 4 only I would not see any of the other districts on my edit page, i only see district 4 and the ops centers and projects under district 4. I need to see the other districts, would a subquery help with this? 

    select district_access_id,district_user_nm,district_role,district_id,district_name,operation_center_id,operation_center_name,oc_district_id,project_name_id,project_name,project_oc_id
    from district_access
    left join districts ON district_access.district_access_id = districts.district_id
    left join operation_centers ON districts.district_id = operation_centers.oc_district_id
    left join projects ON operation_centers.operation_center_id = projects.project_oc_id
    where district_user_nm = '#URL.user_id#' AND oc_district_id <> '' and project_oc_id <> '' OR district_user_nm = ''
Thanks,

Steve


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>