1

I want to insert values into a SQL Server table, but every time I get

"Cannot insert the value NULL into column 'ddod'" error.

[ddod] [datetime] NOT NULL

I'm not inserting NULL value, but 0000-00-00 00:00:00.000, because no datetime was chosen.

Is 0000-00-00 00:00:00.000 the same as NULL?

Thanks a lot for help

2
  • 1
    0000-00-00 00:00:00.000 is not a valid datetime and would fail anyway. How are you inserting this? Commented Oct 6, 2011 at 12:18
  • What is the valid zero datetime, I've something like this 1900-01-01 00:00:00.000. I'm using INSERT query. Commented Oct 6, 2011 at 12:21

1 Answer 1

3

'0000-00-00 00:00:00.000' is not a valid datetime

select CAST('0000-00-00 00:00:00.000' as datetime)

gives the following error

The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

Do you have the following options off?

set arithabort off
set ansi_warnings off

select CAST('0000-00-00 00:00:00.000' as datetime)

In that case it gets cast to NULL instead.

Is there any reason you are not using NULL anyway to represent the absence of a value rather than a "magic" sentinel value?

Sign up to request clarification or add additional context in comments.

1 Comment

@PeterO - The minimum datetime is '1753-01-01 00:00:00.000'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.