473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Problem with Insert/update query with null values

139 100+
Hi,

My database user has just decided that a recent text field in my database needs to be numeric so that some calculations can be run. I've changed it to a double so I can keep the point formatting (ie. 4.1).

I have changed the data types and altered my variables to insert numbers. I have added a default value of 0 to new records added to the database.

Howevern, some of the existing records have a null field in this changed column.
CF can display them but won't update the field without erroring out if the field is left blank.

Expand|Select|Wrap|Line Numbers
  1. PowerRating = <cfif IsDefined("form.PowerRating") AND #form.PowerRating# NEQ "">
  2.         #form.PowerRating#
  3.         <cfelse>
  4.         NULL
  5.         </cfif>,
Any idea what I am doing wrong?
Thanks
Neil
May 11 '09 #1

✓ answered by acoder

The following code:
Expand|Select|Wrap|Line Numbers
  1. PowerRating = <cfif IsDefined("form.PowerRating")>
  2.     <cfif #form.PowerRating# NEQ "">
  3.         <cfset PowerRating = #form.PowerRating#>
  4.     <cfelse>
  5.         NULL
would result in the output "PowerRating = " when there's a value because you've set a variable but you haven't output anything. Your original code would work.

8 5994
acoder
16,027 Expert Mod 8TB
What's the error message? Have the NULL values in the existing fields been set by the query or the default used to be null?
May 11 '09 #2
ndeeley
139 100+
@acoder
It's a basic sytnx error:

ODBC Error Code = 37000 (Syntax error or access violation)
[Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.

The null values are set by the query.
This is the code that adds a new record:

Expand|Select|Wrap|Line Numbers
  1. <cfif IsDefined("form.PowerRating") AND #form.PowerRating# NEQ ""> 
  2.     #form.PowerRating# 
  3.       <cfelse> 
  4.     NULL 
  5.   </cfif>,
This is the code that updates it if their is a change:

Expand|Select|Wrap|Line Numbers
  1. PowerRating = <cfif IsDefined("form.PowerRating")>
  2.     <cfif #form.PowerRating# NEQ "">
  3.         <cfset PowerRating = #form.PowerRating#>
  4.     <cfelse>
  5.         NULL
  6.     </cfif>
..which works if the valeu is NULL, but not if it has retrieved any other value.
May 11 '09 #3
acoder
16,027 Expert Mod 8TB
The following code:
Expand|Select|Wrap|Line Numbers
  1. PowerRating = <cfif IsDefined("form.PowerRating")>
  2.     <cfif #form.PowerRating# NEQ "">
  3.         <cfset PowerRating = #form.PowerRating#>
  4.     <cfelse>
  5.         NULL
would result in the output "PowerRating = " when there's a value because you've set a variable but you haven't output anything. Your original code would work.
May 11 '09 #4
ndeeley
139 100+
It does!

Thanks acoder!
May 11 '09 #5
acoder
16,027 Expert Mod 8TB
Just a point to bear in mind: in queries where you accept user input as values, you should use cfqueryparam to insert/update values in the database.
May 11 '09 #6
ndeeley
139 100+
No problem - are there any tutorials on using it?
May 11 '09 #7
acoder
16,027 Expert Mod 8TB
Yes, there's a few. Here's one from the horse's mouth.
May 11 '09 #8
ndeeley
139 100+
That's grand - thanks!
May 12 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Gunnar Vøyenli | last post by:
Hi Some days ago I posted a problem with a query. Thaks to Dave and John, I got a little closer to a solution. Their suggestion was a solution to my problem as I stated it, but the real problem...
13
by: kieran | last post by:
Hi, I have the following SQL statement which is pulling a few details from a database. As you can see, there is only the one table from which i am creating a temporary copy. The reason I do...
3
by: Myron | last post by:
I'm trying to create a query that will tell me which requests took longer than 10 days to move one from particular state to another state. The query I've created returns the correct requests, but...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
10
by: Florian G. Pflug | last post by:
Hi I installed a postgres-application (which was developed on debian woody) on red hat 9 today, using the postgres 7.3 rpms from redhad. One of my the triggers uses the pg_settings table (more...
13
by: Lee | last post by:
Hello All, First of all I would like to say thank you for all of the help I have received here. I have been teaching myself Access for about 4 years now and I've always been able to find a...
3
by: teddysnips | last post by:
I need a trigger (well, I don't *need* one, but it would be optimal!) but I can't get it to work because it references ntext fields. Is there any alternative? I could write it in laborious code...
6
by: PW | last post by:
I've created an ASP application which uses an Access database. I've created an outer join query, but for some reason the "Property_Def" column is not aligning with the "ESPN" column. They should...
2
by: mob1012 via DBMonster.com | last post by:
Hi All, I wrote last week about a trigger problem I was having. I want a trigger to produce a unique id to be used as a primary key for my table. I used the advice I received, but the trigger is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.