...

View Full Version : Updating table - problem with blank fields (ColdFusion)



WillowFae
01-10-2005, 03:19 PM
am updating a table using a standard insert statement with information from a form. However if a field is blank in the form it is inserting a default value - either 01/01/00 for date or 0 for int. What I want is that if the field is blank then nothing gets updated. There are no default values set in the database.

This is my insert code

<cfquery name="updateBasics" datasource="db">
update tblThesis set
thesisEX13Recd = '#form.frm_ex13#',
thesisExamPanelAppointed = '#form.frm_panel#',
thesisVivaDate = '#form.frm_viva#',
ExamResultID = '#form.frm_result#'
where thesisID = #session.thesis.thesisID#
</cfquery>

I've tried the following but I get an error (I'm hoping I don't have to do it like this and put in an if clause for every field!).

<cfquery name="updateBasics" datasource="db">
update tblThesis set
thesisEX13Recd = '#form.frm_ex13#',
thesisExamPanelAppointed = '#form.frm_panel#',
<cfif #form.frm_viva# is not "">
thesisVivaDate = '#form.frm_viva#',
</cfif>
ExamResultID = '#form.frm_result#'
where thesisID = #session.thesis.thesisID#
</cfquery>

Noodles24
02-08-2005, 03:01 AM
What error are you doing?

You could always do:

<cfparam name="variablename" default="0">

And if it's not already set then it will be defaulted to 0. Do this before the query



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum