insert blank / null date field into database using coldfusion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ndeeley
    New Member
    • Mar 2007
    • 139

    insert blank / null date field into database using coldfusion

    Hi,

    How do I insert a null or blank field into a database using coldfusion? I'm new to CF and its proviing a bit tricky!

    My database date field accepts null values (I think - theres no default value or validation rule).

    The input box on the form is this:
    <input type="text" name="QuotePDat e" maxlength="10" size="12" />

    and is handled by the action form as this:

    insert into tblWorkshops
    (QuotePDate etc..)
    values
    (#form.QuotePDa te#, etc

    How can I get the database to accept the null value? The users of the form won't need to always enter a date, tho they may need to update it later on.

    Thanks!
    Neil
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Why not have null as the default in the database and not insert anything for the date value if it's not input. To do this, just check the value input by the user. If it's empty, don't add to the list of fields to insert.

    Comment

    • ndeeley
      New Member
      • Mar 2007
      • 139

      #3
      Originally posted by acoder
      Why not have null as the default in the database and not insert anything for the date value if it's not input. To do this, just check the value input by the user. If it's empty, don't add to the list of fields to insert.
      Thanks acer - but how exactly do I do this?

      Neil

      Comment

      • ndeeley
        New Member
        • Mar 2007
        • 139

        #4
        Sorry - I meant acoder, not acer. Monday morning...

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          In your query, just add cfifs for the checking, e.g.
          Code:
          insert into tblWorkshops
          (<cfif form.QuotePDate neq "">QuotePDate,</cfif>...)
          values
          (<cfif form.QuotePDate neq "">#form.QuotePDate#,</cfif>)

          Comment

          • ndeeley
            New Member
            • Mar 2007
            • 139

            #6
            Originally posted by acoder
            In your query, just add cfifs for the checking, e.g.
            Code:
            insert into tblWorkshops
            (<cfif form.QuotePDate neq "">QuotePDate,</cfif>...)
            values
            (<cfif form.QuotePDate neq "">#form.QuotePDate#,</cfif>)

            Thats great, thanks for your help!

            Neil

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              You're welcome :)

              Comment

              Working...