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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-09-10 : 08:48:57
|
| Ed writes "I have a realtime History Table: TagG, Value, TimeDateStampI Need SQL Server Query result to return the MAX(value) of each Tag recorded for a particular Date.Strait forward approach:SELECT Tag, TimeDateStamp, MAX(Value) as 'MaxValue'FROM dbo.HistoryWHERE TimeDateStamp BETWEEN date1 AND date2ORDER BY TagDoesn't work!In MS ACCESS:SELECT [tb1].[Tag], [tb1].['MaxValue'], First([History].[DateTimeStamp]) AS FirstOfDateTimeStampFROM [SELECT History.Tag, Max(History.Value) AS ['MaxValue'] FROM History WHERE (((History.DateTimeStamp) Between date1 And date2)) GROUP BY History.Tag ]. AS tb1 INNER JOIN History ON ([tb1].['MaxValue']=[History].[Value]) AND ([tb1].[Tag]=[History].[Tag])GROUP BY [tb1].[Tag], [tb1].['MaxValue']ORDER BY [tb1].[Tag];This works in ACCESS. But not in SQL Server.:(Any ideas?" |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2004-09-10 : 08:49:48
|
| Have you tried:SELECT Tag, TimeDateStamp, MAX(Value) as 'MaxValue'FROM dbo.HistoryWHERE TimeDateStamp BETWEEN date1 AND date2GROUP BY Tag, TimeDateStampORDER BY Tag |
 |
|
|
|
|
|