Connecting Tech Pros Worldwide Help | Site Map

insert blank / null date field into database using coldfusion

Member
 
Join Date: Mar 2007
Posts: 94
#1: Oct 3 '08
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="QuotePDate" maxlength="10" size="12" />

and is handled by the action form as this:

insert into tblWorkshops
(QuotePDate etc..)
values
(#form.QuotePDate#, 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's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Oct 3 '08

re: insert blank / null date field into database using coldfusion


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.
Member
 
Join Date: Mar 2007
Posts: 94
#3: Oct 6 '08

re: insert blank / null date field into database using coldfusion


Quote:

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
Member
 
Join Date: Mar 2007
Posts: 94
#4: Oct 6 '08

re: insert blank / null date field into database using coldfusion


Sorry - I meant acoder, not acer. Monday morning...
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#5: Oct 6 '08

re: insert blank / null date field into database using coldfusion


In your query, just add cfifs for the checking, e.g.
Expand|Select|Wrap|Line Numbers
  1. insert into tblWorkshops
  2. (<cfif form.QuotePDate neq "">QuotePDate,</cfif>...)
  3. values
  4. (<cfif form.QuotePDate neq "">#form.QuotePDate#,</cfif>)
Member
 
Join Date: Mar 2007
Posts: 94
#6: Oct 6 '08

re: insert blank / null date field into database using coldfusion


Quote:

Originally Posted by acoder

In your query, just add cfifs for the checking, e.g.

Expand|Select|Wrap|Line Numbers
  1. insert into tblWorkshops
  2. (<cfif form.QuotePDate neq "">QuotePDate,</cfif>...)
  3. values
  4. (<cfif form.QuotePDate neq "">#form.QuotePDate#,</cfif>)


Thats great, thanks for your help!

Neil
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#7: Oct 6 '08

re: insert blank / null date field into database using coldfusion


You're welcome :)
Reply