比较datetime列值时,行不受影响

时间:2016-04-19 07:21:33

标签: sql sql-server

UPDATE       Production
SET          mylocalcol = '22/4/2016 06:13:55 AM'
WHERE        (LocalCol = '2016-04-18 11:51:00 AM ')

mylocalcol数据类型为nvarcharLocalCol数据类型为datetime

当我执行上面的查询时,它会影响行,即2518行

但当我执行这个......之后2518即2519

UPDATE       Production
SET          mylocalcol = '22/4/2016 06:13:55 AM'
WHERE        (LocalCol = '2016-04-18 11:56:29 AM ')

零行受影响

1 个答案:

答案 0 :(得分:0)

根据您的评论,LocalCol的类型为DateTime;话虽如此,它也将存储毫秒。由于00毫秒,您的第一个查询可能会影响行。请检查数据并相应地更改查询。你可以尝试:

UPDATE       Production
SET          mylocalcol = '22/4/2016 06:13:55 AM'
WHERE        (LocalCol >='2016-04-18 11:56:29 AM' AND LocalCol <'2016-04-18 11:56:30 AM')