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 |
|
p.shaw3@ukonline.co.uk
Posting Yak Master
103 Posts |
Posted - 2005-11-13 : 12:45:04
|
| If I use this query:select distinct PERSONKEYIDS.FullName AS 'Sales Manager Name',Timesheets.SMID, Timesheets.[date]from AGENT_TEAM_FACT left join PERSONKEYIDSON AGENT_TEAM_FACT.ParentKeyID = PERSONKEYIDS.PersonKeyIdINNER JOIN Timesheets on PERSONKEYIDS.PersonKeyId = Timesheets.SMIDOrder by 'Sales Manager Name'I get these resultsSales Manager Name SMID Datedavid hall 10334 11/11/2005david hall 10334 08/11/2005ian lowe 12446 11/11/2005debbi tomms 12211 10/11/2005debbi tomms 12211 09/11/2005debbi tomms 12211 06/11/2005steve vine 13429 07/11/2005Whereas if I add the following line to the query:select distinct PERSONKEYIDS.FullName AS 'Sales Manager Name',Timesheets.SMID, Timesheets.[date]from AGENT_TEAM_FACT left join PERSONKEYIDSON AGENT_TEAM_FACT.ParentKeyID = PERSONKEYIDS.PersonKeyIdINNER JOIN Timesheets on PERSONKEYIDS.PersonKeyId = Timesheets.SMIDwhere convert(DateTime,[date],103) = (Select max(convert(DateTime,[Date],103 )) from Timesheets)Order by 'Sales Manager Name'I of course get this:Sales Manager Name SMID Datedavid hall 10334 11/11/2005ian lowe 12446 11/11/2005Although I can see that both these result sets are correct in relation to the query, These are not what I want. I need a result set that returns the details of the Sales Managers for the most recent date they submitted a Timesheet only. So, for example the result set should look like this:Sales Manager Name SMID Datedavid hall 10334 11/11/2005ian lowe 12446 11/11/2005debbi tomms 12211 10/11/2005steve vine 13429 07/11/2005returning the details for the Sales Managers for the last date on which they submitted a Timesheet ONLY. I hope this makes sense. |
|
|
coolerbob
Aged Yak Warrior
841 Posts |
Posted - 2005-11-13 : 13:30:22
|
| ah, one of the classics. do you have any idea how many times people have asked this question?you wanna do a join on a virtual table that has max(Timesheets.[date]) as one of it's columnshere's just one example:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=36643type this into google for more: max date recent site:www.sqlteam.com |
 |
|
|
|
|
|