Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Stuck on a query

Author  Topic 

mlawton40
Starting Member

15 Posts

Posted - 2007-03-05 : 10:28:24
Hi I have the following tables:

document_area: doc_area_id(int) and doc_area_name(string).
document_area_access: doc_area_id(int) and username(string).

I am trying to do a select statement in an sqldatasource in .net that will select all the document_area.doc_area_name's where the current users username is in the document_area_access using the doc_area_id to link the tables.

Any suggestions?
Cheers, Mark

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-03-05 : 12:59:43
This is a basic joined query, you need to learn SQL. Here's the query, you'll need to pass the current username from your .NET code as a command parameter. I'm assuming that username's are not SQL Server users? If SQL Server users then the second query may do it, depending on exactly what you're storing in the username column in document_area_access.
SELECT doc_area_name 
FROM document_area da
INNER JOIN document_area_access daa ON da.doc_area_id = daa.doc_area_id
WHERE daa.username = @username

SELECT doc_area_name 
FROM document_area da
INNER JOIN document_area_access daa ON da.doc_area_id = daa.doc_area_id
WHERE daa.username = current_user

Try
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -