You must Sign In to post a response.
  • Category: SQL Server

    Query to delete dates

    Dear all,

    In database more than 5 years events are stored.we need to delete 2012 to 2014 events only from the database.Kindly give me some idea to perform this.


    Thanks in advance
  • #763136
    Hello Ellakiya,

    You can use below query :

    DELETE FROM TableName WHERE MemoDate BETWEEN '05/06/2015' and '11/06/2015'

    Date Format should be : MM/dd/yyyy

    Normally SQL Follow MM/dd/yyyy format. As most of Databases follows this format.


    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763147
    Hi,

    use below syntax to delete the records between 2 dates.

    DELETE FROM TABLENAME
    WHERE DATEFIELD BETWEEN FROMDATE AND TODATE


    Note: FromDate & ToDate should be based on your datatype of the date field.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #763151
    Hai Ellakiya,
    You can use simple delete query by passing the date range as below:

    Delete from EventTable
    Where EventDate >= '01/01/2012'
    And EventDate <= '31/12/2014'

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #763215
    Hi,

    DELETE ORDERS WHERE OrderDate BETWEEN '2012-01-01' AND '2014-31-12'

    Hope this will help.

    Regards
    Sriram.R

  • #763294
    Hello,

    Please try with the following query :-

    Delete From TableName Where DateColumnName Between '20120101' AND '20141231'

    TableName - please provide your Event Table name.

    DateColumnName - please provide your Date Column name.

    Thanks

  • #763388
    We have the SQL Function year. You can use that

    Delete From MyTableName Where year(MyColumnName) >= 2011 and year(MyColumnName) <= 2014

    By Nathan
    Direction is important than speed

  • #763689
    Hi

    You know the deleting record date limit means use :
    DELETE from TableName Where datefiled between fromDate and ToDate

    if You know the year means use:
    DELETE from TableName Where year(datefiled) between year(fromDate) and year(ToDate)


Sign In to post your comments