Click here to Skip to main content
15,905,323 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a SQL command that pulls data from a database to show a list of systems a user has access to but as i am new to SQL i am unsure of how to change it to show what systems the user does not have access to.

So if i have access to 3 of 5 systems i need the command to show me the other 2 systems i do not have access to.

SQL
select udesc.description
from u_systems_dev usys, u_user_systems_dev udesc
where usys.system_id = udesc.id
and   usys.user_id = 'username';


I know it sounds simple but this has stumped for a couple days after trying to take parts of it to make a new command i cant get it working.

Would it be something like this?..

XML
select udesc.description
from u_usystems_dev usys, u_user_systems_dev udesc
where usys.system_id <> udesc.id
and   usys.user_id <> 'username';



Thank you
Posted
Updated 12-Jan-15 1:11am
v3

Hi Try this :

SQL
select udesc.description
from u_systems_dev usys
where usys.system_id NOT IN (selct id from u_user_systems_dev )
 
Share this answer
 
Try this: it should show every row from usys (with the row data - probably some name - you want to show) and the description for those items the user has rights to.

If you want only udesc.description then write ISNULL(udes.description, "NO RIGHTS") - ISNULL is sql server function, in oracle use NVL(udesc.description, "NO RIGHTS")

Both functions will return text NO RIGHTS if udesc.description is NULL (i.e. the user has no rows in udesc.



SQL
select usys.some-field, udesc.description
from u_systems_dev usys
LEFT JOIN u_user_systems_dev udesc ON  usys.system_id = udesc.id
WHERE
usys.user_id = 'username';


If this helps please take time to accept the solution. Thank you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900