Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2005 使用时间戳删除查询不正常_Sql Server 2005 - Fatal编程技术网

Sql server 2005 使用时间戳删除查询不正常

Sql server 2005 使用时间戳删除查询不正常,sql-server-2005,Sql Server 2005,我有一张这样的桌子 ID InsertDateTime 1 2012-03-28 07:21:09.717 2 2012-03-28 07:22:09.717 3 2012-03-28 01:21:09.717 4 2012-03-28 03:21:09.717 5 2012-03-28 09:21:09.717 6 2012-03-23 07:21:09.717 7 2012-03-24 07:22:

我有一张这样的桌子

 ID   InsertDateTime  
 1      2012-03-28 07:21:09.717
 2      2012-03-28 07:22:09.717
 3      2012-03-28 01:21:09.717
 4      2012-03-28 03:21:09.717
 5      2012-03-28 09:21:09.717
 6      2012-03-23 07:21:09.717
 7      2012-03-24 07:22:09.717
delete from table1 where  InsertDateTime  ='2012-03-28'
现在我只需要删除特定日期的数据,我尝试这样做,但不起作用:

delete from table1 where  InsertDateTime  ='2012-03-28'
从表1中删除
其中InsertDateTime>='20120328'和
插入日期时间<'20120329'

由于您在数据库中输入的时间是“2012-03-28 07:21:09.717”格式, 当您编写这样的查询时

 ID   InsertDateTime  
 1      2012-03-28 07:21:09.717
 2      2012-03-28 07:22:09.717
 3      2012-03-28 01:21:09.717
 4      2012-03-28 03:21:09.717
 5      2012-03-28 09:21:09.717
 6      2012-03-23 07:21:09.717
 7      2012-03-24 07:22:09.717
delete from table1 where  InsertDateTime  ='2012-03-28'
它将假定为“2012-03-28 00:00:00.000”。但由于您没有该时间戳,它无法工作

所以试着给予

delete from table1 where InsertDateTime >= '2012-03-28' and InsertDateTime < '2012-03-29'
从表1中删除,其中InsertDateTime>='2012-03-28'和InsertDateTime<'2012-03-29'