10e5x
10e5x

Reputation: 909

How to assign null value in datetime field

I have tried:

CAST(NULL AS DATETIME) AS Exit_T.

Give me the following error:

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

Are we able to assign null values to DateTime fields? I need this after query hit some conditions

Upvotes: 0

Views: 4206

Answers (2)

user166390
user166390

Reputation:

If datetime field is a NULL-able field, we can assign the NULL values, otherwise, we can't able to assign the NULL values.

See how the issue is not the cast, but must rather come from elsewhere:

select CASE(NULL AS DATETIME) AS Exit_T;

Upvotes: 1

JVC
JVC

Reputation: 570

What are you trying to do? You don't typically use NULL in a cast. You would assign the keyword NULL to the value of the field. Nulls are acceptable in DateTime fields if you allow it.

Upvotes: 2

Related Questions