sql >> Database teknologi >  >> RDS >> Sqlserver

Behov for at beregne efter afrundet tid eller dato tal i sql server

Du kan bruge den samme teknik til at afrunde til et hvilket som helst datointerval. Dette afhænger af heltals division

SELECT DATEADD(minute, DATEDIFF(minute, 0, foo), 0), -- whole minute DATEADD(minute, DATEDIFF(minute, 0, foo) / 5 * 5, 0), -- 5 minute DATEADD(minute, DATEDIFF(minute, 0, foo) / 10 * 10, 0), -- 10 minute DATEADD(minute, DATEDIFF(minute, 0, foo) / 15 * 15, 0), -- 15 minute DATEADD(minute, DATEDIFF(minute, 0, foo) / 30 * 30, 0), -- 30 minute DATEADD(hour, DATEDIFF(hour, 0, foo), 0), -- whole hour DATEADD(hour, DATEDIFF(hour, 0, foo) / 2 * 2, 0), -- 2 hour DATEADD(day, DATEDIFF(day, 0, foo), 0), -- whole day DATEADD(day, DATEDIFF(day, 0, foo) / 5 * 5, 0), -- 5 day DATEADD(day, DATEDIFF(day, 0, foo) / 10 * 10, 0), -- 10 day DATEADD(month, DATEDIFF(month, 0, foo), 0), -- whole month DATEADD(month, DATEDIFF(month, 0, foo) / 2 * 2, 0) -- 2 month FROM @dates;

  1. Fang duplikatindtastning Undtagelse

  2. Find manglende sekvenshuller mysql

  3. Hvordan genereres tabel API-pakke i Oracle SQL Developer?

  4. Hvordan OPDATERE en kolonne ved hjælp af en anden kolonne i en anden tabel? SQL-fejl:ORA-00933:SQL-kommando blev ikke afsluttet korrekt