Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    LadyDee is offline Novice
    Windows 10 Access 2019
    Join Date
    Mar 2024
    Posts
    18

    Cool



    Quote Originally Posted by Minty View Post
    Given your test data in a table called Test_1 With Fields Called [Timestamp], NValue, TxtCode, the following does what you want.

    Code:
    SELECT 
        [Timestamp],  NValue, TxtCode
        FROM
        (
        SELECT 
        ROW_NUMBER() OVER(Partition By Interval_15  Order BY [TimeStamp] ) as RowNum,*
    
        FROM (
            SELECT 
            DATEADD(MINUTE, FLOOR(DATEDIFF(MINUTE, '2020-01-01', [TIMESTAMP]) / CAST(15 AS DECIMAL)) * 15, '2020-01-01') AS Interval_15,* 
            From 
            Test_1
            ) as q1
    
        ) as q2
      Where RowNum = 1
    Results
    Code:
    Timestamp               NValue          TxtCode
    2021-01-11 11:30:09.000    0.9014763960    A
    2021-01-11 11:45:09.000    0.8264825220    B
    2021-01-11 12:00:09.000    0.0000000000    C
    2021-01-11 12:15:09.000    0.0000000000    A
    The Row_Number is a T_SQL window function. If you just run the centre query (q1) on it's own, then the second one (q2) with the first one it will become obvious how they work.

    You could probably mash it all into one massive Select statement but it's easier to see what is happening with the sub queries.
    Thank you Minty - this works!

  2. #17
    LadyDee is offline Novice
    Windows 10 Access 2019
    Join Date
    Mar 2024
    Posts
    18
    Quote Originally Posted by NoellaG View Post
    About SQL windowing functions: the included zip file contains my basic SQL training - you'll find examples of windowing functions on page 33
    Thank you very much NoellaG. I will review it closely over the weekend

  3. #18
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Quote Originally Posted by LadyDee View Post
    Thank you Minty - this works!
    Glad it helped.
    Note, that the hard coded "start dates" ('2020-01-01') will need to be before any of your existing or possible record dates, so you might want to put them further back to something like '1900-01-01'

    The windowing functions in SQL Server are awesome and fast, and make some things soooo much easier than they would be in Access.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 10-08-2020, 04:31 PM
  2. Replies: 8
    Last Post: 03-14-2012, 05:40 PM
  3. Replies: 1
    Last Post: 01-17-2012, 02:51 PM
  4. Urgent issue! Create field for intervals
    By Bjorn in forum Queries
    Replies: 3
    Last Post: 02-10-2010, 10:26 AM
  5. Help with Time Intervals
    By ddog171 in forum Queries
    Replies: 3
    Last Post: 03-07-2006, 06:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums