Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
CREATE TABLE tasks ( id INT, start_date DATE, ende_date DATE, name VARCHAR(50), position INT NULL ); WITH DateSeries AS ( SELECT task_id, DATEADD(DAY, n, start_date) AS calendar_date FROM ( SELECT id AS task_id, start_date, DATEDIFF(DAY, start_date, ende_date) AS date_range FROM tasks ) t CROSS APPLY (SELECT TOP (t.date_range + 1) ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) - 1 AS n FROM master.dbo.spt_values) AS numbers ) SELECT ds.task_id AS id, ds.calendar_date, t.name AS task_name, t.position FROM DateSeries ds JOIN tasks t ON ds.task_id = t.id ORDER BY ds.task_id, ds.calendar_date;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear