删除两个日期之间的数据 [英] delete data in between two dates
问题描述
我想从sql格式的数据库中删除数据到ToDate
例如,
假设我从2012年9月1日到30/9有一个月的记录/ 2012。我想删除12/9/2012至2012年9月20日的记录。这可能吗?如果有任何解决方案PLZ帮助我这个。谢谢。
i want to delete data from database in sql form date to ToDate
eg,
Suppose i have one month record from 1/9/2012 to 30/9/2012. and i want to delete Record From 12/9/2012 to 20/9/2012 .is it possible? if any have solution plz help me out this. thank you.
推荐答案
DELETE FROM MyTable WHERE DateField BETWEEN "12/09/2012" to "20/09/2012"
关于运营商: http://msdn.microsoft.com/en-us/library/ms187922.aspx [ ^ ]
我假设你正在使用SQLServer,但由于此运算符是sql标准运算符,因此您也可以在其他引擎中找到它。顺便说一句,你可以简单地使用这个:
About between operator: http://msdn.microsoft.com/en-us/library/ms187922.aspx[^]
I assumed you are using SQLServer, but since this operator is an sql standard one, you will find it also in other engines. Btw, you can simply have the same with this one:
DELETE FROM MyTable WHERE DateField >= "12/09/2012" AND DateField <= "20/09/2012"
如果要删除两个日期之间的记录,您只需将其放入WHERE
子句中的信息如下:
If you want to delete records between two dates, you would just put that information in theWHERE
clause like so:
DELETE
FROM myTable
WHERE myDate >= '12/9/2012' AND myDate <= '20/9/2012'
I首先将它作为 SELECT
语句运行,以确保在实际运行删除之前获得正确的记录。基本上,只需将 DELETE
替换为 SELECT *
,如下所示:
I would run that as a SELECT
statement first to make sure you are getting the right records before actually running the delete. Basically, just replace the DELETE
with SELECT *
like so:
SELECT *
FROM myTable
WHERE myDate >= '12/9/2012' AND myDate <= '20/9/2012'
DELETE FROM tableName WHERE myDate BETWEEN @StartDate AND @endDate
http://msdn.microsoft.com/en-us/ library / ms187922.aspx [ ^ ]
这篇关于删除两个日期之间的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!