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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Visual Studio - Query syntax

Author  Topic 

jewel
Starting Member

18 Posts

Posted - 2004-10-06 : 19:47:33
Hi all - my last query for today lol.

my query so far is
SELECT FirstName, LastName, Phone, CallPrompt AS Title, Date2
FROM dbo.Client
WHERE (Date2 < '2004-09-30 00:00:00')
ORDER BY Date2

this works fine - but I have now been asked to change it to include the last call date - which means I now need to do a join with the call table - one (Client)to many (Call)relationships


Client (dbo) ClientCode and Call(dbo) ClientCode

If I add from Call (dbo) the LogDatTim field - how do I tell it I only want the last date used.

thanks

Pat Phelan
Posting Yak Master

187 Posts

Posted - 2004-10-08 : 14:00:10
I'd use:
 SELECT *
FROM Call AS a
WHERE a.LogDatTim = (SELECT Max(b.LogDatTim)
FROM Call AS b
WHERE b.ClientCode = a.ClientCode)
-PatP
Go to Top of Page
   

- Advertisement -