SQL Query for time data only
Thanx,
Pete
SELECT *
FROM Table
JOIN (SELECT IdColumn, convert(varchar(10), YourColumn, 101) DateColumn, max(YourColumn)
FROM Table
WHERE CONVERT(VARCHAR(10), YourColumn, 108) > '12:05:00 PM'
GROUP BY idColumn, convert(varchar(10), YourColumn, 101)
) t1 ON TAble.IdColumn = t1.IdColumn
Looking for relevant Development Whitepapers? Visit the SearchWinDevelopment.com Research Library.
Mrdenny | Apr 17 2008 7:40PM GMT
Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.
C Pete | Apr 17 2008 7:59PM GMT
Thanks, Mrdenny, but that’s not quite there yet. The situation is that the government NOAA has a database somewhere in the universe that logs data from hundreds of stations all over the world at random intervals. There may be one or ten entries for temperatures between 11:30 am and 12:30 pm on any particular day. What I need is to ask for the records closest to 12:00 pm for every day for the last several years. I’ll then be able to use Excel to figure an average noontime temperature for whatever calendar period. My problem is that the date and time data is stored as one number so I can’t just say “WHERE time between hh:mm:ss AND hh:mm:ss. It doesn’t seem to be able to figure the time without the date too and I can’t type in a date for each day in the decade. I forgot to mention, this isn’t a programming task; it’s just a manual query type in from the keyboard whenever someone asks for the info - so no programming examples, please!
Mrdenny | Apr 18 2008 6:39PM GMT
Any query examples would be able to be used as one off queries to dump the data so it can be loaded into excel.
The only way to get this data out will be with a bit of SQL code.
I assume that the database is running SQL Server? If it’s running a different database platform that will change the query a bit.