我要生成一个月份的日期列表,像这样日期
2006-6-1
2006-6-2
2006-6-3
2006-6-4
..
..
..
..
一直到
2006-6-30用一个sql语句生成,望各大侠赐教,多谢

解决方案 »

  1.   

    select dateadd(day,1,'2006-6-1')
    用这个函数,在指定的日期上加一天.循环即OK。
      

  2.   

    别人的例子:set rowcount 31
    select identity(int,0,1) as id into # from sysobjects
    set rowcount 0declare @t table(Date varchar(10))insert into @t select convert(char(10),dateadd(dd,id,'2006-06-01'),120) from # --where datediff(mm,dateadd(dd,id,'2006-03-01'),'2006-03-01')=0select * from @tdrop table #
      

  3.   

    DECLARE @t TABLE (
      Times DATETIME)DECLARE
      @starttiem DATETIME,
      @endtime   DATETIMESELECT @starttiem = '2006-1-1',
           @endtime = '2006-6-30'WHILE @starttiem <= @endtime
      BEGIN
        INSERT INTO @t
        SELECT @starttiem
        SET @starttiem = Dateadd(DAY,1,@starttiem)
      ENDSELECT *
    FROM   @t
      

  4.   

    set rowcount 31
    select identity(int,0,1) as id into # from sysobjects
    set rowcount 0declare @t table(Date varchar(10))insert into @t select convert(char(10),dateadd(dd,id,'2006-06-01'),120) from # where datediff(mm,dateadd(dd,id,'2006-03-01'),'2006-03-01')=0select * from @tdrop table #
      

  5.   


    declare @i int
    declare @date smalldatetime
    set @i=1
    set @date='2006-6-1'
    while @i<>-1
    begin
    if month(dateadd(day,@i,@date))=month(@date)
    begin
    print dateadd(day,@i,@date)
    set @i=@i+1
    end
    else  
    set @i=-1
    end
      

  6.   

    回这么快,多谢各位不用临时表有办法吗?只用一个select
      

  7.   

    只用一个select,不用临时表,不用循环,是不可能的.
      

  8.   

    以下方式可以生成最多10000天(若需超过此限制,稍作修改即可)的任意期间内的日历表。declare @BDate datetime,@EDate datetime
    set @BDate ='2006-06-01'
    set @EDate = '2006-06-30'select dateadd(day,id-1,@BDate) from (
    select id=a.id+b.id*10+c.id*100+d.id*1000+1 from 
    (
    select id=0 union all select 1
    union all select id=2 union all select 3
    union all select id=4 union all select 5
    union all select id=6 union all select 7
    union all select id=8 union all select 9
    ) a,(
    select id=0 union all select 1
    union all select id=2 union all select 3
    union all select id=4 union all select 5
    union all select id=6 union all select 7
    union all select id=8 union all select 9
    ) b,(
    select id=0 union all select 1
    union all select id=2 union all select 3
    union all select id=4 union all select 5
    union all select id=6 union all select 7
    union all select id=8 union all select 9
    ) c,(
    select id=0 union all select 1
    union all select id=2 union all select 3
    union all select id=4 union all select 5
    union all select id=6 union all select 7
    union all select id=8 union all select 9
    ) d
    ) aa
    where id<=datediff(day,@BDate,@EDate)+1
    order by id
      

  9.   

    txlicenhe(马可) 
    牛!我要100天就行了,呵呵,这个鱼跟"渔"也差不多了,多谢多谢各位相助
      

  10.   

    这哪是一条SQL,这跟我数据库里放个表,存1-1w的数据有什么区别?