This is a lovely little bit of SQL which I can’t write. 🙂
what I need to do is this;
select the latest value from the table (CreatedOn), for each user, for a specific StatID. I need to then join the usertable (ssUSER) and select the u.username and I also need to join the detailstatid from the table. I.e. I just need the latest result from this table for each user and then do a join on the user and detailstatid.
SELECT TOP 1000
[DetailStatUserLogID]
,[UserID]
,[DetailStatID]
,[OverviewID]
,[Count]
,[StatPercent]
,[SpecificDate]
,[CreatedOn]
,[ModifiedOn]
,[Note]
,[LoggedDate]
,[OverViewGUID]
FROM [StartStop].[dbo].[DetailStatUserLog]
SELECT TOP 1000
[DetailStatID]
,[DetailStatGUID]
,[NameOfStat]
,[DetailOfStat]
,[CreatedByType]
,[DataType]
,[CreatedByGUID]
,[CreatedBy]
,[ModifiedOn]
,[CreatedOn]
,[OverviewID]
FROM [StartStop].[dbo].[DetailStat]
SELECT TOP 1000
[UserID]
,[EmailAddress]
,[Authenticated]
,[UserName]
FROM [StartStop].[dbo].[ssUsers]
Thanks for any help you might be able to give. 🙂
Try: