null date

Post Reply
sourceuno
Posts: 225
Joined: Mon Apr 09, 2001 3:58 pm

null date

Post by sourceuno »

How can I insert a NULL value into a date type column? I tried using:

insert mytable values(NULL)

But that doesn't work.
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

null date

Post by Kai »

Quote the NULL:

insert into mytable values('NULL');
sourceuno
Posts: 225
Joined: Mon Apr 09, 2001 3:58 pm

null date

Post by sourceuno »

I'm actually trying to add a date column to a table by creating a new table with the new column and then trying to insert the data from the old table into the new table, but I get the following error:

Types for field ErrDate are not compatible date != char

Here's what I'm doing:

error1 is identical to error2 but doesn't have the date field Errdate.

create table error2(id counter,Errdate date, field1 varchar(80))
insert into error 2 select id,'NULL',field1 from error1
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

null date

Post by Kai »

Explicitly convert the NULL:

insert into error2 select id, convert('NULL', 'date'), field1 from error1;
Post Reply