Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: RE: Sorting by a group by


Message #1 by David Cameron <dcameron@i...> on Fri, 1 Jun 2001 10:02:14 +1000
Hi David,
Thanks for the reply. I am storing data in SQL 7 and all queries etc. are 
in an Access 2000 Datqabase .MDB, linking in with ODBC drivers (i need 
this because of another file I need to connect to). I also do name fields 
more explicitly but stripped it down (unnecessarily?) for here.
Sorry, I missed something important (oops!). I need the returned query 
recordset to be editable. I got something close to your code and tested it 
in an access query, but i believe it is always the MAX and GROUP BY 
commands that make it non-editable.
Temporarily I have a small VB program i wrote on a 1 hour scheduler to get 
the max call date and place it in a field in the TblCompanies table which 
solves this but it is so nasty....
Is there an option that is nicer?

See Ya

Jeff
> Try something like this
> 
> SELECT TblCompanies.*, MAX(tblCalls.CallDate)
> FROM TblCompanies
>     INNER JOIN tblCalls ON
>     tblCalls.IdLinkKey = tblCompanies.ID
> WHERE TblCompanies.Rep = 12 AND TblCalls.Closed = 0
> GROUP BY tblCompanies.*
> 
> You must also name the specific fields in tblCompanies that you want and
> include them in the GROUP BY statement. At the moment the statement will 
not
> work until you do.
> 
> ie SELECT TblCompanies.MyField ...(rest of the query goes here)
>    GROUP BY TblCompanies.My Field
> 
> If there is a chance that no 'calls' have been made by a company, but you
> still want to return a record, change the join to a LEFT OUTER join. 
Also is
> this for Access 2000 or SQL Server 7? There is a fair difference between
> them. 
> 
> David Cameron
> nOw.b2b
> dcameron@i...

  Return to Index