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

前端 未结 3 1287
有刺的猬
有刺的猬 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:22

    One way would be with a CTE:

    with cte_dates as (
      select cast('20110119' as datetime) as [date]
      union all
      select dateadd(dd, 1, [date])
          from cte_dates
          where dateadd(dd, 1, [date]) <= '20111231'
    )
    select [date], YourColumn
        from cte_dates
            left join YourTable
                on ...
    option (maxrecursion 0);
    

提交回复
热议问题