首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql大侠

2012-05-08 
sql在线等大侠idtimestamp12012-5-4 17:07:3522012-5-4 17:07:3532012-5-4 17:07:35。。。如何更新使得下一条

sql在线等大侠
id timestamp
1 2012-5-4 17:07:35
2 2012-5-4 17:07:35
3 2012-5-4 17:07:35
。。。

如何更新使得下一条记录中timestamp的值是上一条中时间+1 第一条的时间不变。坐等大侠

[解决办法]

SQL code
DECLARE @timestamp DATETIME UPDATE TAB SET   @timestamp = CASE WHEN @timestamp IS NULL THEN timestamp ELSE DATEADD(SECOND,1,@timestamp) END  ,timestamp = @timestamp
[解决办法]
SQL code
--> 测试数据:[test]if object_id('[test]') is not null drop table [test]create table [test]([id] int,[timestamp] datetime)insert [test]select 1,'2012-5-4 17:07:35' union allselect 2,'2012-5-4 17:07:35' union allselect 3,'2012-5-4 17:07:35'update testset [timestamp]=DATEADD(DD,id-1,(select [timestamp] from test where id=1))select * from test/*id    timestamp1    2012-05-04 17:07:35.0002    2012-05-05 17:07:35.0003    2012-05-06 17:07:35.000*/ 

热点排行