日期:2014-05-16 浏览次数:20487 次
----------------------------------------------------------------
-- Author :DBA_HuangZJ(发粪涂墙)
-- Date :2014-03-20 07:52:53
-- Version:
-- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
-- Apr 2 2010 15:48:46
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据[table2]
if object_id('[table2]') is not null drop table [table2]
go
create table [table2]([id] int,[indate] datetime)
insert [table2]
select 1,'2013-09-19 11:02:00' union all
select 2,'2013-09-19 11:03:00' union all
select 3,'2013-09-15 11:07:00'
--------------生成数据--------------------------
SELECT * FROM [table2]
go
UPDATE [table2]
SET [indate]=DATEADD(dd,-4,[indate])
WHERE [indate] BETWEEN '2013-09-19 00:00:00.000' AND '2013-09-19 23:59:59.997'
go
SELECT * FROM [table2]
----------------结果----------------------------
/*
id indate
----------- -----------------------
1 2013-09-19 11:02:00.000
2 2013-09-19 11:03:00.000
3 2013-09-15 11:07:00.000
(3 row(s) affected)
(2 row(s) affected)
id indate
----------- -----------------------
1 2013-09-15 11:02:00.000
2 2013-09-15 11:03:00.000
3 2013-09-15 11:07:00.000
*/
UPDATE [table2] SET [indate]=DATEADD(dd,-4,[indate]) WHERE [id] BETWEEN 1 AND 2
update table2 set indate=dateadd(dd,-4,indate) where id<3