日期:2014-05-18  浏览次数:20403 次

求SQL语句 在线等
表结构如下  

datetime value 
2011-11-25 2
2011-11-26 3
2011-11-27 4
2011-12-10 5
2011-12-11 6

求大侠指点一sql语句  
将2011-11-25到2011-11-27(时间段作为参数) 的数据添加到2011-11-28 到2011-11-30 添加完成后如下

datetime value 
2011-11-25 2
2011-11-26 3
2011-11-27 4
2011-11-28 2
2011-11-29 3
2011-11-30 4
2011-12-10 5
2011-12-11 6

------解决方案--------------------
insert into a([datetime],[value]) select [datetime]+3[value] 
from a 
where [datetime]>='2011-11-25' and [datetime]<='2011-11-27'
------解决方案--------------------
SQL code
insert into a select datetime+3,value  
from a  
where datetime between '2011-11-25' and '2011-11-27'

------解决方案--------------------
没看懂楼主是什么意思,可参考如下:
SQL code
--获取两个时间之内的所有日期

--sql 2000
declare @sdate datetime
declare @edate datetime
set @sdate = '2011-11-28'
set @edate = '2011-11-30'


select 
    dateadd(dd,num,@sdate) dt
from 
    (select isnull((select count(1) from sysobjects where id<t.id),0) as num from sysobjects t) a
where
    dateadd(dd,num,@sdate)<=@edate

/*
dt                                                     
------------------------------------------------------ 
2011-11-28 00:00:00.000
2011-11-29 00:00:00.000
2011-11-30 00:00:00.000

(所影响的行数为 3 行)
*/

------解决方案--------------------
探讨

SQL code
insert into a select datetime+3,value
from a
where datetime between '2011-11-25' and '2011-11-27'