Cannot delete row due to: out-of-range smalldatetime value

Posted on 2006-03-22
Last Modified: 2008-02-01
I'm having a problem with mssql. I accidentally inserted a value into a smalldatetime field using getdate(). When I try to delete the row using queries like

delete from tborders where nOrderID=1


delete from tborders where Convert(Varchar,dteOrderDate,103) = '22/03/2006'

It gives me the error;

The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value.

Is there another delete statement I could use to get rid of this row?

Thanks in advance for your help.
Question by:PsycheBNP
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    delete from tborders
    where dteOrderDate >= convert(smalldatetime, '22/03/2006', 103)
    AND dteOrderDate < dateadd(day, 1, convert(smalldatetime, '22/03/2006', 103) )
    LVL 75

    Accepted Solution

    > delete from tborders where Convert(Varchar,dteOrderDate,103) = '22/03/2006'

    delete from tborders where Convert(Varchar(10),dteOrderDate,103) = '22/03/2006'

    Author Comment

    Thanks for the fast reply angelIII, unfortunately your query returned the same error.

    Author Comment

    That did the trick aneeshattingal, thank you very much.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now