Sako73
Sako73

Reputation: 10147

Why am I not able to insert a NULL into a nullable DATE column in SQL Server 2008?

I am using SQL Server 2008r2.

I have a table with a column defined as:

TheDate date null

When I try to insert a NULL value into this column, I get the error message: "Operand type clash: int is incompatible with date".

If I change the data type to datetime, it works fine.

Why does this not work with the date data type?

Thanks.

EDIT: Lamak is right:

My insert statement was using a select statement as the source, and the source table was created using a "select into" a temp table statement, and apparently, since the table was dynamically defined, the column was assigned the "int" data type when the null was inserted.

Upvotes: 3

Views: 2854

Answers (1)

Lamak
Lamak

Reputation: 70668

You are not just inserting a NULL, you are inserting a NULL of datatype INT. Insert this instead: CAST(NULL AS DATE)

Upvotes: 11

Related Questions