Hi @CEO ,
Welcome to Microsoft Q&A!
I made a test from my side and could not reproduce your issue.
create table mytable
(formReqNo int,
dateRecord varchar(500))
insert into mytable values
(588399021,'2021-08-09 13:47:36.373'),
(588399021,'2021-08-09 13:47:37.513')
DELETE FROM myTable where formReqNo = 588399021
Above is working with no error.
I also added one more row with wrong date format and changed the where condition but it was still working with no error.
insert into mytable values
(588399021,'2021-08-09 12:66:36.373')
DELETE FROM myTable where dateRecord>='2021-08-09 13:00:37.513'
DELETE FROM myTable where dateRecord between '2021-07-30 09:00:00' and '2021-09-30 09:00:00'
So first of all, we have to correct all the date format of dateRecord column in your table.
Adding to what Erland mentioned, you could also try with below query to find out all incorrect formatted records.
select * from mytable where ISDATE(dateRecord)=0
Besides, you could also try to change the SET DATEFORMAT
, SET LANGUAGE
and default language option settings to see any possibility.
Another way is to use the ISO-8601 date format
that is supported by SQL Server which works always and regardless of your SQL Server language and dateformat settings. One format is YYYY-MM-DDTHH:MM:SS
for dates and times.
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.