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'