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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

optimise query 1

Status
Not open for further replies.

taval

Programmer
Jul 19, 2000
192
GB
strQuery = "SELECT f.CustId, min(f.UploadDate)as FirstDate, max(fd.UploadDate)as LastDate from FileDescription f, FileDescription fd, Customer where
f.CustId = fd.CustId and f.FileID = fd.FileID
and not(DateDiff(day, f.UploadDate, getdate()) > "& numDays & " )
Group by f.CustId Order By f.CustId"


StrQ = "SELECT CustName from Customer where CustID =" & rsbac("CustId")

I currently have two queries, strQuery firstly finds all the CustID's and dates that satisfy the conditions in that SQL string. The second query StrQ finds the CustName using the CustId found from the first query. My question is , is there a way of elminating the StrQ by enabling the first query to extract the CustName as well. I've tried puting CustName in the select part of the first query but I get errors.

Grateful for any help.
Thanks.
 
You have the Customer table in your query, but you don't have it properly joined to one of the other tables. Try this:

[tt]strQuery = "SELECT f.CustId, min(f.UploadDate)as FirstDate, max(fd.UploadDate)as LastDate, custname from FileDescription f, FileDescription fd, Customer c where
f.CustId = fd.CustId and f.FileID = fd.FileID and c.custid = f.custid and not(DateDiff(day, f.UploadDate, getdate()) > "& numDays & " )
Group by f.CustId Order By f.CustId"
[/tt]
 
Thank you Robert, you pointed me on the right track and I got the new query to work.
happy.gif


Taha
 
I think if you make the first query a view and then make the second query a join with the view it will eliminate the error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top