Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
creating_date_ranges [2018/05/13 16:58] – created david | creating_date_ranges [2025/03/27 15:42] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== SQL Server ====== | ||
<code sql> | <code sql> | ||
WITH date_range AS ( | WITH date_range AS ( | ||
Line 22: | Line 23: | ||
AND DateAdd(DAY, | AND DateAdd(DAY, | ||
ORDER BY TheDate DESC | ORDER BY TheDate DESC | ||
+ | ; | ||
+ | |||
+ | WITH date_list AS ( | ||
+ | SELECT DateAdd(DAY, | ||
+ | | ||
+ | | ||
+ | FROM sys.all_objects | ||
+ | ) | ||
+ | SELECT TheDate | ||
+ | FROM date_list | ||
+ | WHERE TheDate BETWEEN ' | ||
+ | AND ' | ||
+ | ORDER BY TheDate | ||
+ | ; | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====== Oracle ====== | ||
+ | |||
+ | <code sql> | ||
+ | WITH date_list AS ( | ||
+ | SELECT TRUNC(SYSDATE) - rownum proc_date | ||
+ | FROM dual | ||
+ | | ||
+ | ) | ||
+ | SELECT proc_date | ||
+ | FROM date_list | ||
+ | ORDER BY proc_date | ||
; | ; | ||
- | WITH date_list AS ( | + | FUNCTION get_date_range |
- | SELECT TRUNC(SYSDATE) - rownum proc_date | + | (process_id IN NUMBER |
- | FROM dual | + | ) RETURN SYS_REFCURSOR |
- | | + | IS |
- | ) | + | c SYS_REFCURSOR; |
- | SELECT proc_date | + | BEGIN |
- | FROM date_list | + | OPEN c FOR |
- | ORDER BY proc_date | + | WITH date_list AS ( |
- | ; | + | SELECT TRUNC(SYSDATE) - rownum proc_date |
- | + | FROM dual | |
- | + | | |
- | | + | ) |
- | (process_id IN NUMBER | + | SELECT proc_date |
- | ) RETURN SYS_REFCURSOR | + | FROM date_list |
- | IS | + | ORDER BY proc_date |
- | c SYS_REFCURSOR; | + | ; |
- | BEGIN | + | |
- | OPEN c FOR | + | RETURN c; |
- | WITH date_list AS ( | + | END; |
- | SELECT TRUNC(SYSDATE) - rownum proc_date | + | |
- | FROM dual | + | |
- | | + | |
- | ) | + | |
- | SELECT proc_date | + | |
- | FROM date_list | + | |
- | ORDER BY proc_date | + | |
- | ; | + | |
- | | + | |
- | RETURN c; | + | |
- | END; | + | |
-- Past | -- Past | ||
- | | + | |
- | SELECT TRUNC(SYSDATE) - rownum proc_date | + | SELECT TRUNC(SYSDATE) - rownum proc_date |
- | FROM dual | + | FROM dual |
- | | + | |
- | ) | + | ) |
- | SELECT proc_date | + | SELECT proc_date |
- | FROM date_list | + | FROM date_list |
- | ORDER BY proc_date | + | ORDER BY proc_date |
- | ; | + | ; |
-- Future | -- Future | ||
- | | + | |
- | SELECT TRUNC(SYSDATE) + rownum proc_date | + | SELECT TRUNC(SYSDATE) + rownum proc_date |
- | FROM dual | + | FROM dual |
- | | + | |
- | ) | + | ) |
- | SELECT proc_date | + | SELECT proc_date |
- | FROM date_list | + | FROM date_list |
- | ORDER BY proc_date | + | ORDER BY proc_date |
- | ; | + | ; |
-- Range | -- Range | ||
- | | + | WITH date_list AS ( |
- | SELECT TRUNC(SYSDATE) - rownum proc_date | + | SELECT TRUNC(SYSDATE) - rownum proc_date |
- | FROM dual | + | FROM dual |
- | | + | |
- | ) | + | ) |
- | SELECT proc_date | + | SELECT proc_date |
- | FROM date_list | + | FROM date_list |
- | | + | |
- | | + | |
- | ORDER BY proc_date | + | ORDER BY proc_date |
- | ; | + | ; |
-- Range (past) | -- Range (past) | ||
- | | + | WITH date_list AS ( |
- | SELECT TRUNC(SYSDATE) - rownum proc_date | + | SELECT TRUNC(SYSDATE) - rownum proc_date |
- | FROM all_tab_cols -- Just use a big table | + | FROM all_tab_cols -- Just use a big table |
- | ) | + | ) |
- | SELECT proc_date | + | SELECT proc_date |
- | FROM date_list | + | FROM date_list |
- | | + | |
- | | + | |
- | ORDER BY proc_date | + | ORDER BY proc_date |
- | ; | + | ; |
- | </ | + | </ |