I have a table like so:
enrollments
---------------------
ID - INT
Name - VARCHAR(45)
DateOfBirth - DateTime
The DateOfBirth field should be optional and allow NULLs if there is
nothing present.
How do I do this in my INSERT?
I've tried:
INSERT INTO enrollments (Name, DateOfBirth)
VALUES ('Joe', (SELECT IF(LENGTH({date_of_birth}) = 0, NULL,
'{date_of_birth}')))
The {date_of_birth} is a variable and is provided by the client
application. I can assure that is either a valid date format or empty
string.
Error I am getting:
You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near ') = 0,
NULL, '')),
Is there a better way to handle optional dates that I am missing?
Constructive criticism welcome.
Thanks,
--
James Neff
Technology Specialist
Tethys Health Ventures
4 North Park Drive, Suite 203
Hunt Valley, MD 21030
office: 410.771.0692 x103
cell: 443.865.7874
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]