Subject Re: [firebird-support] Noobie Null Date and Time woes
Author Aage Johansen
sbdlinxg wrote:
> I've just discovered Firebird and I'm using VB to experiment with it.
> This code works fine
>
> myDate = Format(Now(), "mm/dd/yy hh:mm")
> sql = "INSERT INTO MYTABLE (MYDATE) VALUES ('" & myDate & "');"
>
> as long as myDate is a date. If I set myDate = NULL the statement
> causes an error and I know why the error is occurring.
> What I need to know is how to write this statement to take into
> account the possibility that myDate is NULL.


The usual way is to use a parameterised query:
insert into MYTABLE (MYDATE) values (:MYDATE)
and set the parameter to the date value (with no conversion or formatting)
- which makes it independent of the format of a "date string".
If this is not possible in VB (I've never used it), you might get away with
an explicit test in your program (pseudocode):
if date is Null then
insert into MYTABLE (MYDATE) values (Null)
else
insert into MYTABLE (MYDATE) values (yourdatestring)

--
Aage J.