日期:2014-05-17 浏览次数:20476 次
select info_time, dateadd(dd,1,info_time) from stu_Info
----------------------------
-- Author :TravyLee(物是人非事事休,欲语泪先流!)
-- Date :2012-11-23 08:57:22
-- Version:
-- Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
-- Jul 9 2008 14:43:34
-- Copyright (c) 1988-2008 Microsoft Corporation
-- Developer Edition on Windows NT 6.1 <X86> (Build 7601: Service Pack 1)
--
----------------------------
--> 测试数据:[test]
if object_id('[test]') is not null drop table [test]
go
create table [test]([info_Time] datetime)
insert [test]
select '2012-11-22 13:54:56.000' union all
select '2012-11-22 13:57:12.000' union all
select '2012-11-22 13:58:42.000' union all
select '2012-11-22 13:58:48.000' union all
select '2012-11-22 14:00:05.000' union all
select '2012-11-22 14:03:14.000' union all
select '2012-11-22 14:03:50.000' union all
select '2012-11-22 09:48:26.000' union all
select '2012-11-22 11:00:36.000' union all
select '2012-11-22 11:00:36.000'
select * from [test]
go
--更新
update test
set [info_Time]=dateadd(dd,1,[info_Time])
--直接查询
select dateadd(dd,1,[info_Time]) as [info_Time] from test
/*
info_Time
-----------------------
2012-11-23 13:54:56.000
2012-11-23 13:57:12.000
2012-11-23 13:58:42.000
2012-11-23 13:58:48.000
2012-11-23 14:00:05.000
2012-11-23 14:03:14.000
2012-11-23 14:03:50.000
2012-11-23 09:48:26.000
2012-11-23 11:00:36.000
2012-11-23 11:00:36.000
(10 行受影响)
*/
若果是datetime类型
update stu_Info set info_Time=info_Time+1
如果是string,varchar类型
update stu_Info set info_Time=replace(info_Time,'2012-11-22','2012-11-23')
if object_id('[stu_info]') is not null drop table [stu_info]
go
create table [stu_info] (info_Time datetime)
insert into [stu_info]
select '2012-11-22 13:54:56.000' union all
select '2012-11-22 13:57:12.000' union all
select '2012-11-22 13:58:42.000' union all
select '2012-11-22 13:58:48.000' union all