Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Average value after 3 time intervals.

Average value after 3 time intervals.

Scheduled Pinned Locked Moved Database
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robert Vrinceanu
    wrote on last edited by
    #1

    I have a simple table with 3 fields: ID, Tag1, Data ID      Tag1            Data ________________________________ 1     2     6/1/2009 22:00 2     1     6/1/2009 23:00 3     2     6/2/2009 6:00 4     3     6/2/2009 7:00 5     2     6/2/2009 8:00 6     2     6/2/2009 9:00 7     2     6/2/2009 10:00 8     1     6/2/2009 11:00 9     2     6/2/2009 11:30 10     1     6/2/2009 13:00 11     2     6/2/2009 14:00 12     2     6/2/2009 15:00 13     2     6/2/2009 16:00 14     1     6/2/2009 17:00 15     2     6/2/2009 18:00 16     1     6/2/2009 19:00 17     1     6/2/2009 20:00 18     2     6/2/2009 21:00 19     2     6/2/2009 22:00 20     3     6/2/2009 23:00 21     1     6/2/2009 23:59 22     2     6/3/2009 1:00 23     3     6/3/2009 2:00 24     2     6/3/2009 3:00 25     3     6/3/2009 4:00 26     2     6/3/2009 5:00 27     3     6/3/2009 6:00 28     2     6/3/2009 7:00 29     3     6/3/2009 8:00 30     2     6/3/2009 9:00 31     3     6/3/2009 10:00 32     2     6/3/2009 11:00 33     1     6/3/2009 11:55 34     2     6/3/2009 22:00 35     2     6/

    L 1 Reply Last reply
    0
    • R Robert Vrinceanu

      I have a simple table with 3 fields: ID, Tag1, Data ID      Tag1            Data ________________________________ 1     2     6/1/2009 22:00 2     1     6/1/2009 23:00 3     2     6/2/2009 6:00 4     3     6/2/2009 7:00 5     2     6/2/2009 8:00 6     2     6/2/2009 9:00 7     2     6/2/2009 10:00 8     1     6/2/2009 11:00 9     2     6/2/2009 11:30 10     1     6/2/2009 13:00 11     2     6/2/2009 14:00 12     2     6/2/2009 15:00 13     2     6/2/2009 16:00 14     1     6/2/2009 17:00 15     2     6/2/2009 18:00 16     1     6/2/2009 19:00 17     1     6/2/2009 20:00 18     2     6/2/2009 21:00 19     2     6/2/2009 22:00 20     3     6/2/2009 23:00 21     1     6/2/2009 23:59 22     2     6/3/2009 1:00 23     3     6/3/2009 2:00 24     2     6/3/2009 3:00 25     3     6/3/2009 4:00 26     2     6/3/2009 5:00 27     3     6/3/2009 6:00 28     2     6/3/2009 7:00 29     3     6/3/2009 8:00 30     2     6/3/2009 9:00 31     3     6/3/2009 10:00 32     2     6/3/2009 11:00 33     1     6/3/2009 11:55 34     2     6/3/2009 22:00 35     2     6/

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, I'm no SQL expert however IMO DATEPART(hour, DataTime) BETWEEN DATEPART(hour,'10:30:00 PM') AND DATEPART(hour,'06:30:00 AM') can't be right since that ignores the half hours completely. Can't you just use some function to get the time, something like TIME(DataTime) NOT BETWEEN '06:30:00' AND '22:30:00'? BTW: I felt a need to eliminate the 12hour timing, and to invert the statement. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


      R 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, I'm no SQL expert however IMO DATEPART(hour, DataTime) BETWEEN DATEPART(hour,'10:30:00 PM') AND DATEPART(hour,'06:30:00 AM') can't be right since that ignores the half hours completely. Can't you just use some function to get the time, something like TIME(DataTime) NOT BETWEEN '06:30:00' AND '22:30:00'? BTW: I felt a need to eliminate the 12hour timing, and to invert the statement. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        R Offline
        R Offline
        Robert Vrinceanu
        wrote on last edited by
        #3

        Thanks for your answer. Unfortunately, I can't waive these time intervals. What I don't understand is why SELECT ID FROM dbo.TableTest WHERE Data BETWEEN CONVERT(DATETIME,(CONVERT(varchar(10),Data, 101)+ ' 10:00:00 PM'),101) AND CONVERT(DATETIME,(CONVERT(varchar(10),DATEADD(DAY,1,Data), 101)+ ' 06:00:00 AM'),101) return this:                           and not return: ID                              ID __                              __ 1                              1 2                              2 19                              3 20                              19 21                              20 34                              21 35                              22                               23                               24                               25                               26              &nbs

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups