Sqlserver
 sql >> Teknologi Basis Data >  >> RDS >> Sqlserver

SQL Server 2008 Hasilkan Serangkaian waktu tanggal

Gunakan CTE rekursif

declare @StartTime datetime = '2011-07-20 11:00:33',
    @EndTime datetime = '2011-07-20 15:37:34',
    @Interval int = 554 -- this can be changed.

;WITH cSequence AS
(
    SELECT
       @StartTime AS StartRange, 
       DATEADD(SECOND, @Interval, @StartTime) AS EndRange
    UNION ALL
    SELECT
      EndRange, 
      DATEADD(SECOND, @Interval, EndRange)
    FROM cSequence 
    WHERE DATEADD(SECOND, @Interval, EndRange) < @EndTime
)
 /* insert into tmp_IRange */
SELECT * FROM cSequence OPTION (MAXRECURSION 0);


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Izin EXECUTE ditolak pada objek 'xxxxxxx', basis data 'zzzzzzz', skema 'dbo'

  2. Mengoptimalkan Hapus di SQL Server

  3. Impor Tanggal String di kolom Derived

  4. ORDER BY item harus muncul dalam daftar pilih jika pernyataan berisi operator UNION, INTERSECT atau KECUALI (SQL Server)

  5. Bagaimana saya bisa memasukkan nilai acak ke dalam tabel SQL Server?