Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need to insert null into date field

Posted on 2007-08-05
4
Medium Priority
?
5,766 Views
Last Modified: 2013-12-24
I am using MySql 5 and Coldfusion 8 to insert some dates into a table.  I want to be able to insert a null value into a date field if that is possible. Basically, if the field is blank, do not insert anything to the date field.  When I try to insert nothing into the field I get the following error...

Data truncation: Incorrect date value: '' for column 'my_date_field' at row 1

Is there anyway to do this?
0
Comment
Question by:MFredin
4 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 500 total points
ID: 19636005
Hi,

if you use the word NULL in your string ie

insert into yourTable (yourDate, yourOtherField) values (NULL, "ASDF")

then the date field would be null otherwise if you put a normal date in then it should work,

I'm not sure what code that you are using - additionally, your table needs to have allow nulls for this field on this table.
0
 
LVL 10

Expert Comment

by:js_vaughan
ID: 19636322
There was a topic on this just a few days ago, check it out: http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_22734308.html
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 19638105

Simply test your field and then use NULL if it does not hold a date.

<cfset form.theDate = "">

 insert into your Table (dateField)
 values (
   <cfif isDate(form.dateField)>#createODBCdate(form.dateField)#<cfelse>NULL</cfif>
 )

 or if you prefer the cfquerparam method..

 insert into your Table (dateField)
 values (
   <cfqueryparam cfsqltype="CF_SQL_DATE" value="#form.theDate#" <cfif NOT IsDate(form.theDate)>NULL="true"</cfif> >
   )

0
 

Author Comment

by:MFredin
ID: 19639426
Oh IC.  I was using ' ' around NULL ('NULL').  When I removed them it worked.

Thanks.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month20 days, 17 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question