读书人

修改时间列的值解决办法

发布时间: 2012-03-22 17:43:57 作者: rapoo

修改时间列的值
XX表中有个字段名为DateCreated的项,datetime格式
例如其中某项值为'2011-09-01 21:23:45:233'
现在我要将其修改为我指定的一个时间例如'2011-09-01 22:32:13:132'时间无规律 随意定


修改语句
update XX set dateCreated = '2011-09-01 22:32:13:132' where dateCreated = '2011-09-01 21:23:45:233'

报错是字段由字符串转换成时间错误 我想 知道 datecreated = 后面怎么写才能是正确的格式

[解决办法]

SQL code
------------------------------ Author  :fredrickhu(小F,向高手学习)-- Date    :2011-09-15 16:08:34-- Verstion:--      Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (Intel X86) --    Apr 22 2011 11:57:00 --    Copyright (c) Microsoft Corporation--    Enterprise Evaluation Edition on Windows NT 6.1 <X64> (Build 7600: ) (WOW64)--------------------------------> 测试数据:[tb]if object_id('[tb]') is not null drop table [tb]go create table [tb]([col] datetime)insert [tb]select '2011-09-01 21:23:45:233'--------------开始查询--------------------------update tb set col = '2011-09-01 22:32:13:132' where col = '2011-09-01 21:23:45:233'select * from [tb]----------------结果----------------------------/* col-----------------------2011-09-01 22:32:13.133(1 行受影响)*/
[解决办法]
SQL code
update XX set dateCreated = '2011-09-01 22:32:13.132' where dateCreated = '2011-09-01 21:23:45.233'
[解决办法]
SQL code
DECLARE @TB TABLE(id int,DDate datetime)INSERT INTO @TB(id,DDate)SELECT 1,GETDATE()SELECT * FROM @TBUPDATE @TBSET DDate  = '2011-01-01 01:00:02:001'SELECT * FROM @TB
[解决办法]
毫秒最大是999,写4位不是找错吗

读书人网 >SQL Server

热点推荐