generate sql temp table of sequential dates to left outer join to

前端 未结 3 1288
有刺的猬
有刺的猬 2020-12-18 05:34

i have a table of data that i want to select out via stored proc such that users can connect a MS excel front end to it and use the raw data as a source to graph.

T

3条回答
  •  一生所求
    2020-12-18 06:26

    Another way to do it is with a memory table. It won't choke due to recursion limitations like some of the above solutions.

    DECLARE @dates AS TABLE ([Date] date);
    
    DECLARE @date date = {d '2010-10-01'};
    DECLARE @endDate date = {d '2010-11-01'};
    
    while (@date < @endDate)
    BEGIN
        INSERT INTO @dates VALUES (@date);
        SET @date = dateadd(DAY, 1, @date)
    END
    SELECT * FROM @dates;
    

    SQL Fiddle

提交回复
热议问题