Solved

ColdFusion Update Number Type Field in Access

Posted on 2012-12-20
5
324 Views
Last Modified: 2012-12-20
My website accepts number values and I receive an error if no value is inputted. (only works when a value is present)

Problem:
I would like to delete this value if needed without receiving this error:
Data type mismatch in criteria expression

My Access database has a number type field and using cf_sql_varchar in my update statement.
I've tried using other cf_sql types: number, integer, etc without success.

Would the solution be to insert a default value of 0 if no data is present or to change the cf_sql statement that would accept a null value for the number type field in Access?
0
Comment
Question by:DJPr0
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:jdthedj
ID: 38710884
You could use the IsNumeric function to check the value before adding to your database.  It is not a CF_SQL_VARCHAR which is for text.  I assume you are using <CFQUERYPARAM>  If you are (and you should be) you don't specify any CFSQLTYPE
0
 

Author Comment

by:DJPr0
ID: 38710986
You could use the IsNumeric function to check the value before adding to your database.

How will this help to delete the value?

I want to update the field to null or 0.
0
 
LVL 3

Expert Comment

by:jdthedj
ID: 38711002
Try this

<CFFUNCTION NAME="NullVal" RETURNTYPE="Numeric">
  <CFARGUMENT NAME="Amt" DATATYPE="String" REQUIRED="True">
  <CFIF IsNumeric(Amt)>
    <CFRETURN Amt>
  <CFELSE>
    <CFRETURN 0>
  </CFIF>
</CFFUNCTION>

The function will change any null to a zero
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 38711291
I want to update the field to null or 0.

EDIT To set the value to 0, use the val() function.  It automatically converts non-numeric values like an empty string to  0.  (I'm assuming your column type is INTEGER. Change if needed ...)

              UPDATE TableName
              SET  NumColumn = <cfqueryparam value="#val(form.yourVariable)#" cfsqltype="cf_sql_integer">
              WHERE ID = ....

To set the value to null, use the NULL attribute

              UPDATE TableName
              SET       NumColumn = <cfqueryparam value="#form.yourVariable#"
                                                      cfsqltype="cf_sql_integer"
                                                      null="#not IsNumeric(form.yourVariable)#" >
              WHERE ID = ....


Would the solution be to insert a default value of 0 if no data is present or to change the cf_sql statement that would accept a null value for the number type field in Access?

All depends on your needs.  Sometimes 0 is better, other times null is.  When I want to indicate something has no value, like for a date field, I prefer NULL instead of entering a bogus date like 12/31/1899. For numbers it can go either way.
0
 

Author Closing Comment

by:DJPr0
ID: 38711745
Worked perfectly, thanks _agx_!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now