Skip to main content
Inspiring
October 5, 2012
Answered

Update date field to a Null

  • October 5, 2012
  • 1 reply
  • 1338 views

Hi everyone,

   I have a web page called Quality that has mulitple records on it with multiple people logged into it at the same time updating it.I’m trying to update a date on one field, and it works, but then if I try to clear it out and update it, it doesn’t update it to a Null. When I put in the code to try and update it as a Null in the Update Query, it puts a date of 1/1/00 in the field for some reason and also updates the other blank fields to this date. I have something to account for the Nulls on the drop downs in my other fields. The code I used for those was like this in the Update Query:

Set Approval_Initials = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Evaluate('form.PDF_Creation_Doc_Control_Approval_Initials#id#')#" null="#NOT len(trim(Evaluate('form.PDF_Creation_Doc_Control_Approval_Initials#id#')))#" />

   Do I have to use something like this again for the Date field except with the CF_SQL_DATE tag? Below is what I have for the Date field right now:

<cfif DisplayQualityDate.recordcount>

<cfif isDefined("form.Quality_Date#id#") and evaluate("form.Quality_Date#id#") neq "">

<cfquery Datasource="#application.DataSource#">

Update Approval

Set Approval_Date = '#Evaluate("form.Quality_Date#id#")#'

WHERE APV_ItemID = #id# AND Document_Type = 'Quality'

</cfquery>

</cfif>

  </cfif>

Is this enough information? What does the CF_SQL_DATE do exactly? Any help would be greatly appreciated.


Andy

    This topic has been closed for replies.
    Correct answer Carl Von Stetten

    Andy,

    A couple of things to think about:

    1. Are the date columns in your database set up to accept nulls?
    2. Does the database recognize dates in the format that your users are entering them (i.e.: "m/d/yy")?

    You should be able to use similar logic with the cfqueryparam null= on your form field data.  CF_SQL_DATE will tell your database that the value being passed is a date and not some other type of data.

    -Carl V.

    1 reply

    Carl Von Stetten
    Carl Von StettenCorrect answer
    Legend
    October 5, 2012

    Andy,

    A couple of things to think about:

    1. Are the date columns in your database set up to accept nulls?
    2. Does the database recognize dates in the format that your users are entering them (i.e.: "m/d/yy")?

    You should be able to use similar logic with the cfqueryparam null= on your form field data.  CF_SQL_DATE will tell your database that the value being passed is a date and not some other type of data.

    -Carl V.

    Inspiring
    October 5, 2012

    Carl,

       Thank you very much! I tried it again and it works now! I know I tried this before, but I must not have had the date field name correct. I think I also still had this in the code: and evaluate("form.Quality_Date#id#") neq ""   That seemed to cause problems with it not updating the date field to a blank. I'll try some more testing, but I think it's fixed now! Thanks again!

    Andy