If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > NULL date value

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-27-03, 08:37
angelc angelc is offline
Registered User
 
Join Date: Nov 2003
Posts: 3
NULL date value

I am trying to insert value into a table by selecting from another table.
say into table1 from table2
table1-field1,field2,field3(nullable and type date),field4
table2-fld1,fld2
If I give

Insert into table1
select fld1,'abc',NULL,fld2
from table2

I get an error NULL is not a field in the inserted or selected table.

If I give

Insert into table1
select fld1,'abc','',fld2
from table2

It gives invalid date format error message.

Could someone please tell me how I can insert Null value to date field by using select statement??????????
Reply With Quote
  #2 (permalink)  
Old 11-27-03, 09:16
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Re: NULL date value

Quote:
Originally posted by angelc
I am trying to insert value into a table by selecting from another table.
say into table1 from table2
table1-field1,field2,field3(nullable and type date),field4
table2-fld1,fld2
If I give

Insert into table1
select fld1,'abc',NULL,fld2
from table2

I get an error NULL is not a field in the inserted or selected table.

If I give

Insert into table1
select fld1,'abc','',fld2
from table2

It gives invalid date format error message.

Could someone please tell me how I can insert Null value to date field by using select statement??????????
INSERT INTO TABLE1 (FIELD1, FIELD2, FIELD4)
SELECT FLD1, 'abc', FLD2 FROM TABLE2
Reply With Quote
  #3 (permalink)  
Old 11-27-03, 09:49
Walter Janissen Walter Janissen is offline
Registered User
 
Join Date: Nov 2003
Location: Germany
Posts: 62
In DB2 V7 there is the function NULLIF, which returns NULL, if both arguments are the same, i.e NULLIF(CURRENT DATE, CURRENT DATE) results in NULL.
Reply With Quote
  #4 (permalink)  
Old 11-27-03, 11:59
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
You can use
cast(null as date)
in place of your null in the original post ..

But n_i 's suggestion is the best

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On