ASP Search

J

JP SIngh

Hi All

I am trying to build a search results page for the user.

In the database we have three tables

Employees

Empname - Text
Fullname - Text

Records

Id - Autonumber
Subject - Text
Description - Text

Record Dependents

RecordId - Integer
Username - Text

In record dependents there could be multiple values for each recordid
basically it specifies who is allow to view a particular record.

What I need help with is how do a search that will find what the user has
specified but only bring back results for which he is a RecordDependent.

Can this be done through simple sql? or do I need something more.

I was thinking more on the lines of

"Select * from records where exists (Select * from recorddependents where
empname = '8877YYYY') and description ='" & request.form("description") &
"'"
 
S

Steven Burn

First of all, don't use "Select *"

http://aspfaq.com/show.asp?id=2096

Second, try something along the lines of;

strSQL = "Select [FIELDS] from Records Where [Condition 1]=[Value 1] AND [Condition 2]=[Value 2]"

Replacing [FIELDS] with your field names, and [Condition 1] etc, with the respective conditions and values you want to meet.

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
B

Bullschmidt

And in case you ever need it here is an example of one query (QueryB)
based on the results of another query (QueryA):

QueryA = "SELECT CustID FROM tblCUSTOMERS WHERE CustName = 'A%'"

QueryB = "SELECT CustID, CustName FROM tblCUSTOMERS WHERE CustID IN (" &
QueryA & ")"

But the following is even faster and allows for more than one field to
be returned in QueryA:

QueryB = "SELECT tblCUSTOMERS.CustID, CustName FROM (" & strSQLA & ") AS
tblSQLA INNER JOIN tblCUSTOMERS ON tblSQLA.CustID = tblCUSTOMERS.CustID"

So QueryA would include all the CustID's for customers starting with A.

And QueryB would include more fields in the customers table (i.e. not
just the CustID field) for the records returned in QueryA (which was the
customers starting with A).

I suppose it wouldn't hurt to always use LEFT JOIN's in QueryB and build
from the tblSQLA on the left to other tables that have fields you want
to return.

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top