Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

We are in the process of developing

Status
Not open for further replies.

varnix

Programmer
Jan 7, 2002
94
US
We are in the process of developing an internal app where we check a list contained in the DB that is a CSV list of user ID's that are allowed access to information on a particular resource.

So what we have is a field called 'authusers' that contains something like 1,5,3,2,12, etc - the order depends on when a user was authorized. With '1' being a catchall user for when we want everyone to be guaranteed access to it.

Database structure looks something like:
rname - resource name
rdesc - resource description
authusers - CSV list of authorized users
rcat - resource category

so I run a query such as:
select rcat,rname,rdesc from resources
where '1' in (authusers) or '#userid#' in (authusers)
and rcat like '4'


So with a userid of 3 and a test DB that contains two records where the authusers list is '1,3' and the rcat is '4' and another record where the authusers list is '3' and rcat is '4', I only get the lone record where the authusers is '3' and rcat is '4' returned.

What am I doing wrong in my query? I thought that the 'IN' statement allowed me query a CSV list within the DB.

Any suggestions?
 
no, IN syntax allows you to query a CSV within the sql statement

you could use LIKE

... ','||authusers||',' LIKE '%,'||#userid#||',%'

you need to add the commas so that each term is separate, i.e. to prevent finding 5 in '2,17,45'

rudy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top