December 20, 2007 at 7:17 am
I would like to query for 5 new records everyday. For example, the records at 4am in the morning. I would like to do so without having to enter the date part for each new day. Is there a way of doing so?
Thanks SQL2DAY
December 20, 2007 at 7:27 am
Please will you post your table structure and some sample data and expected results. It's difficult to visualise your problem without this.
John
December 20, 2007 at 7:37 am
John--
Lets see if I can recall from memory--
Select Data_ID, DateTime and Batt_Vltg from tableName where DateTime = Max(DateTime) which would be the current day and additionally where the time = 4am in the morning. This would give all the battery voltages at 4 am for the current day.
Data_ID DateTime Batt_Vltg
1 12/20/2007 04:00 AM 12.2
2 12/20/2007 04:00 AM 12.6
3 12/20/2007 04:00 AM 13.0
SQL2DAY
December 20, 2007 at 9:17 am
You desire query will look like.
SELECT
Data_ID
, DateTime
, Batt_Vltg
FROM
tableName
WHERE
DateTime = CAST((CONVERT(VARCHAR(10),GETDATE(),103) + ' 04:00AM') AS DATETIME)
Current where clause give you your required result.
cheers
December 20, 2007 at 9:37 am
SELECT Data_ID, DateTime, Batt_Vltg
FROM
tableName
WHERE
DateTime = DATEADD(hh,4,DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0))
Doing conversions to Varchar to trim the time off a date is inefficient and CPU intensive.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 20, 2007 at 2:01 pm
Thank You!
I will try and let you know how it does....
Thanks Again..... SQL2DAY
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply