日期:2014-5-18 浏览次数:20055次

请教插入数据问题
表结构
SQL code
CREATE TABLE [dbo].[ERPProjectPhaseTime](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [bianhao] [int] NULL,
    [phase] [int] NULL,
    [starttime] [smalldatetime] NULL,
    [endtime] [smalldatetime] NULL,
    [days] [int] NULL,
    [category] [int] NULL,
    [orderid] [int] NULL,)


表数据
SQL code
insert erpprojectphasetime (ID,bianhao,phase,starttime,endtime,days,category,orderid)  values ( 105,563,1,'2012-05-04 00:00:00.000','2012-05-04 00:00:00.000',1,1,1)
insert erpprojectphasetime (ID,bianhao,phase,starttime,endtime,days,category,orderid)  values ( 106,563,2,'2012-05-06 00:00:00.000','2012-05-06 00:00:00.000',1,1,1)
insert erpprojectphasetime (ID,bianhao,phase,starttime,endtime,days,category,orderid)  values ( 107,563,2,'2012-05-07 00:00:00.000','2012-05-08 00:00:00.000',2,1,1)
insert erpprojectphasetime (ID,bianhao,phase,starttime,endtime,days,category,orderid)  values ( 108,563,3,'2012-05-09 00:00:00.000','2012-05-10 00:00:00.000',2,1,1)
insert erpprojectphasetime (ID,bianhao,phase,starttime,endtime,days,category,orderid)  values ( 109,563,4,'2012-05-11 00:00:00.000','2012-05-11 00:00:00.000',1,1,1)
insert erpprojectphasetime (ID,bianhao,phase,starttime,endtime,days,category,orderid)  values ( 110,563,4,'2012-05-12 00:00:00.000','2012-05-13 00:00:00.000',2,1,1)
insert erpprojectphasetime (ID,bianhao,phase,starttime,endtime,days,category,orderid)  values ( 111,563,4,'2012-05-16 00:00:00.000','2012-05-16 00:00:00.000',1,1,1)
insert erpprojectphasetime (ID,bianhao,phase,starttime,endtime,days,category,orderid)  values ( 112,563,5,'2012-05-17 00:00:00.000','2012-05-17 00:00:00.000',1,1,1)
insert erpprojectphasetime (ID,bianhao,phase,starttime,endtime,days,category,orderid)  values ( 113,563,6,'2012-05-20 00:00:00.000','2012-05-23 00:00:00.000',4,1,1)

现在插入一个新的时间段,在此时间之后的表中数据将要顺延,这个问题比较简单,update starttime=starttime+@days,endtime=endtime+@days where starttime>@endtime,但有一种情况不会顺延,就是像第6行数据和第7行数据之间本身就有空隙,那么新增的时间段只要天数在这个空隙之内的,到第7行就可以不向后顺延了,这个怎么处理呢?

------解决方案--------------------
不明白神马意思