Skip to main content
Known Participant
Mar 13, 2012 5:29 PM UTC
Question

Please help me insert NULL for a date

I have 2 date fields. I would like to be able to leave them blank and have the database create a NULL.

This works fine but only if I have the 2 date fields listed last in my insert statement. If I add any below the 2 shown below, the fields are populated with: 01/01/1900. For example, I can't add the "LastModifiedBy" field below the 2 shown below otherwise it will fill in that database field with 01/01/1900.

Does anyone know what could be causing this? Thank you.

 

  <cfqueryparam value = "#ARGUMENTS.LastModifiedBy#" CFSQLType = "CF_SQL_VARCHAR">,  

  <cfif StructKeyExists( ARGUMENTS, "DateField1" )>
   <cfqueryparam value="#arguments.DateField1#" cfsqltype="CF_SQL_DATE">, 
  <cfelse>
   <cfqueryparam value="" cfsqltype="CF_SQL_DATE" null="yes" >,
  </cfif>

  <cfif StructKeyExists( ARGUMENTS, "DateField2" )>
   <cfqueryparam value="#arguments.DateField2#" cfsqltype="CF_SQL_DATE"> 
  <cfelse>
   <cfqueryparam value="" cfsqltype="CF_SQL_DATE" null="yes" >
  </cfif>
    )
  
  </cfquery>

    This topic is closed to new replies. Start a new post to keep the conversation going.

    12 replies

    prabhup99504277
    Participant
    Feb 24, 2015 2:59 PM UTC

    <cfqueryparam value="#arguments.DateField1#" cfsqltype="CF_SQL_DATE" null="#NOT IsDate(arguments.DateField1)#">


    You will try above one.

    Translate
    pete_freitag
    Participating Frequently
    Mar 14, 2012 4:21 PM UTC

    Why not just use NULL (the SQL Keyword), it's not totally necessary to cfqueryparam it if the value is null.

    Translate
    Inspiring
    Mar 14, 2012 5:58 PM UTC

    >Why not just use NULL (the SQL Keyword), it's not totally necessary to cfqueryparam it if the value is null.

    Duh, good point.

    Translate
    Inspiring
    Mar 13, 2012 9:58 PM UTC

    Can you dump the query and post the generated sql (including the actual values)? Also for query questions, always include your database type.

    I believe you should use CF_SQL_TIMESTAMP instead of CF_SQL_DATE.

    It depends on the database, column type and what value you are inserting.

    Message was edited by: -==cfSearching==-

    Translate
    p_sim
    Participating Frequently
    Mar 13, 2012 8:59 PM UTC

    I believe you should use CF_SQL_TIMESTAMP instead of CF_SQL_DATE. Try it.

    Translate
    Inspiring
    Mar 13, 2012 6:50 PM UTC

    see if your db has a default value.

    Translate
    earwig75Author
    Known Participant
    Mar 13, 2012 7:42 PM UTC

    It doesn't. This only happens if I add things AFTER those 2. If i add everything bofore they enter NULL just fine.

    Translate