Skip to main content
Inspiring
March 10, 2009
Question

DatePart To Select Data at Half Hour Mark

  • March 10, 2009
  • 1 reply
  • 717 views
I have a view in SQL server I am selecting from. I am getting a bunch of timestamped logs. I only want to select the logs at the half hour mark 1:00, 1:30, 2:00, 2:30 etc. The following code works fine:

select PointName, [DateTime], PointValue From dbo.ExtendedLog_view

where PointName IN ('R481A_Litestatus', 'R481_Litestatus','R481A_SpaceHum', 'R481_SpaceHum','R481ASpace' ,'R481Space') and [DateTime] > #DateAdd('h',-12, todayDate)# and DatePart("n", [DateTime]) = '00'

I get all the logs timestamped with a minute of 00. If I add another DatePart factor the page processes and just gets stuck there. Adding an additional "or DatePart("n", [DateTime]) = '30'" seems to lock the page up.

Any ideas as to why this might be happening? Is there any other method I can use to only select logs timestamped on the hafl hour mark?
    This topic has been closed for replies.

    1 reply

    siriivenAuthor
    Inspiring
    March 10, 2009
    NM I ended up figuring it out. I needed parentheses around the whole or statement.

    (DatePart("n", [DateTime]) = '00' or DatePart("n", [DateTime]) = '30' )