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.
| Author |
Topic |
|
jrockfl
Posting Yak Master
223 Posts |
Posted - 2006-06-15 : 17:12:17
|
| I have an application that needs the get the initials and email that the request was last routed to.The header table stores all the requests, the routing table shows who that request was routed to and EmailAddressesses contains all the employees.I want to be able to return the last person the requests where routed to send them an email.Right now it's returning all the routings for each request.This is what I have so far...SELECT Max(Routing.RoutedTo) AS RoutedTo, Header.ID, Max(Routing.Date) AS MaxOfDate, EmailAddresses.EmailFROM (Header INNER JOIN Routing ON Header.ID = Routing.ID) INNER JOIN EmailAddresses ON Routing.RoutedTo = EmailAddresses.InitialsWHERE (((Header.Completed)=0) AND ((Routing.Date)<DateAdd('d',-1,Now())))GROUP BY Header.ID, EmailAddresses.Email;HeaderID1ID RoutedTo1 BBB 06/12/20061 JAC 06/13/2006In this example, it would just return the last row, not both |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-06-15 : 18:24:14
|
| How would you know what the last one was?What is the criteria for "last"?CODO ERGO SUM |
 |
|
|
jrockfl
Posting Yak Master
223 Posts |
Posted - 2006-06-15 : 18:32:29
|
| The most recent date. The one from 06/13, it has been routed to this person last. |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-06-15 : 18:40:40
|
| Is this a Microsoft SQL Server database?I noticed you are using a function called NOW(), and that is not a SQL Server function.CODO ERGO SUM |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-06-16 : 02:27:49
|
If you use MS Access then post your question at Access ForumAlso try thisSelect top 1 * from( yourQuery) T order by [datecol] DESC MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|