generate days from date range

后端 未结 29 2496
渐次进展
渐次进展 2020-11-21 05:19

I would like to run a query like

select ... as days where `date` is between \'2010-01-20\' and \'2010-01-24\'

And return data like:

29条回答
  •  误落风尘
    2020-11-21 06:17

    thx Pentium10 - you made me join stackoverflow :) - this is my porting to msaccess - think it'll work on any version:

    SELECT date_value
    FROM (SELECT a.espr1+(10*b.espr1)+(100*c.espr1) AS integer_value,
    dateadd("d",integer_value,dateserial([start_year], [start_month], [start_day])) as date_value
    FROM (select * from 
        (
        select top 1 "0" as espr1 from MSysObjects
        union all
        select top 1 "1" as espr2 from MSysObjects
        union all
        select top 1 "2" as espr3 from MSysObjects
        union all
        select top 1 "3" as espr4 from MSysObjects
        union all
        select top 1 "4" as espr5 from MSysObjects
        union all
        select top 1 "5" as espr6 from MSysObjects
        union all
        select top 1 "6" as espr7 from MSysObjects
        union all
        select top 1 "7" as espr8 from MSysObjects
        union all
        select top 1 "8" as espr9 from MSysObjects
        union all
        select top 1 "9" as espr9 from MSysObjects
        ) as a,
        (
        select top 1 "0" as espr1 from MSysObjects
        union all
        select top 1 "1" as espr2 from MSysObjects
        union all
        select top 1 "2" as espr3 from MSysObjects
        union all
        select top 1 "3" as espr4 from MSysObjects
        union all
        select top 1 "4" as espr5 from MSysObjects
        union all
        select top 1 "5" as espr6 from MSysObjects
        union all
        select top 1 "6" as espr7 from MSysObjects
        union all
        select top 1 "7" as espr8 from MSysObjects
        union all
        select top 1 "8" as espr9 from MSysObjects
        union all
        select top 1 "9" as espr9 from MSysObjects
        ) as b,
        (
        select top 1 "0" as espr1 from MSysObjects
        union all
        select top 1 "1" as espr2 from MSysObjects
        union all
        select top 1 "2" as espr3 from MSysObjects
        union all
        select top 1 "3" as espr4 from MSysObjects
        union all
        select top 1 "4" as espr5 from MSysObjects
        union all
        select top 1 "5" as espr6 from MSysObjects
        union all
        select top 1 "6" as espr7 from MSysObjects
        union all
        select top 1 "7" as espr8 from MSysObjects
        union all
        select top 1 "8" as espr9 from MSysObjects
        union all
        select top 1 "9" as espr9 from MSysObjects
        ) as c   
    )  as d) 
    WHERE date_value 
    between dateserial([start_year], [start_month], [start_day]) 
    and dateserial([end_year], [end_month], [end_day]);
    

    referenced MSysObjects just 'cause access need a table countin' at least 1 record, in a from clause - any table with at least 1 record would do.

提交回复
热议问题