如何找到两个时间戳记录之间每分钟间隔的所有时间戳值

How to find all the timestamp values interval by each minute between the two timestamp records

我有一个 table 具有三个字段 ID(整数)- 唯一、打开日期(日期时间)、关闭日期(日期时间):

Id  Open Date                  Close Date
1   2019-07-03 16:28:39.497    2019-07-04 16:28:39.497
2   2019-07-04 15:28:39.497    2019-07-05 19:28:39.497
…..N        

我想以每分钟为间隔计算开盘日期和收盘日期之间的所有时间戳。

所以我想要的最终输出是这样的:

Id  Open Date             Close Date                   TimeStamp Range
1   2019-07-03 16:28:39.497   2019-07-04 16:28:39.497   2019-07-03 16:29:00.0000
1   2019-07-03 16:28:39.497   2019-07-04 16:28:39.497   2019-07-03 16:30:00.0000
1   2019-07-03 16:28:39.497   2019-07-04 16:28:39.497   2019-07-03 16:31:00.0000
1   2019-07-03 16:28:39.497   2019-07-04 16:28:39.497   …..........................
1   2019-07-03 16:28:39.497   2019-07-04 16:28:39.497   2019-07-04 16:27:00.0000
2   2019-07-04 15:28:39.497   2019-07-05 19:28:39.497   2019-07-04 15:29:00.0000
2   2019-07-04 15:28:39.497   2019-07-05 19:28:39.497   2019-07-04 15:30:00.0000
2   2019-07-04 15:28:39.497   2019-07-05 19:28:39.497   2019-07-04 15:31:00.0000
2   2019-07-04 15:28:39.497   2019-07-05 19:28:39.497   ….................................
2   2019-07-04 15:28:39.497   2019-07-05 19:28:39.497   2019-07-05 19:27:00.0000
N   …............................   …...........................    …......................................

有人会为此编写 SQL 查询吗?

这是一个使用临时 tally/numbers table 和 Cross Apply

的选项

例子

Declare @YourTable Table ([Id] int,[Open Date] datetime,[Close Date] datetime)  Insert Into @YourTable Values 
 (1,'2019-07-03 16:28:39.497','2019-07-04 16:28:39.497')
,(2,'2019-07-04 15:28:39.497','2019-07-05 19:28:39.497')

Select A.*
      ,TSRange = DateAdd(Minute,N,convert(varchar(16),[Open Date],20))
  From @YourTable A
  Cross Apply (
                Select Top (DateDiff(MINUTE,[Open Date],[Close Date])-1) N=Row_Number() Over (Order By (Select NULL)) 
                  From master..spt_values n1, master..spt_values n2
              )  B

Returns