update a set end_date=end_date+1 where start_date=end_date

解决方案 »

  1.   

    1     2000-1-1    2002-2-2   
    1     2002-2-2    2004-3-3
    1     2004-3-3    2005-5-5id为1的不是有三条记录吗?
    第一条的end_date 等于 下一条(第二条)的start_date =2002-2-2
    所以我就要把第二条的start_date修改为2002-3-2(加一个月)
    以此类推
      

  2.   

    update a set start_date=end_date+1 where start_date=end_date
      

  3.   

    if exists(select * from sysobjects where id=object_id('test'))
      drop table test
    go
    create table test([id] int,start_date datetime, end_date datetime)
    go
    insert into test
    select            1   ,  '2000-1-1' ,   '2002-2-2'
    union all select  1   ,  '2002-3-2' ,   '2004-3-3'
    union all select  1   ,  '2004-4-3' ,   '2005-5-5'
    union all select  2   ,  '2000-6-6' ,   '2002-6-6'
    union all select  2   ,  '2002-7-6' ,   '2004-7-6'
    union all select  2   ,  '2004-7-6' ,   '2005-6-6 '
     
    update test
    set test.start_date=dateadd(month,1,test.start_date)
    where test.start_date in(select end_date from test a where [id]=test.[id] and start_date<test.start_date)select * from test
      

  4.   

    楼上的兄弟,我不是要比较一条记录中的start 和 end
    而是要比较不同记录之间的start 和 end 

    id      start       end
    1     2000-1-1    2002-2-2   第1条(id=1)
    1     2002-2-2    2004-3-3   第2条(id=1)
    1     2004-3-3    2005-5-5   第3条(id=1)举例:我会找所有start(三条)和所有end(三条)是否有相同的值 如果有相同的值
    如 第2条的start=2002-2-2 和 第一条的end=2002-2-2  不是相同吗?
    这样的话我就把第2条的start加一个月
      

  5.   

    update a 
    set a.start_date=dateadd(m,1,b.end_date)
    from 表A a,表A b
    where a.start_date=b.end_date and a.id=b.id
      

  6.   

    谢谢 hb9723(空古)
    不知道where [id]=test.[id] and start_date<test.start_date 中的
    start_date<test.start_date 是何意思啊