473,574 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Insert/update query with null values

139 New Member
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
8 6000
acoder
16,027 Recognized Expert Moderator MVP
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 New Member
@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 Recognized Expert Moderator MVP
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 "PowerRatin g = " 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 New Member
It does!

Thanks acoder!
May 11 '09 #5
acoder
16,027 Recognized Expert Moderator MVP
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 New Member
No problem - are there any tutorials on using it?
May 11 '09 #7
acoder
16,027 Recognized Expert Moderator MVP
Yes, there's a few. Here's one from the horse's mouth.
May 11 '09 #8
ndeeley
139 New Member
That's grand - thanks!
May 12 '09 #9

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

Similar topics

2
2867
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 is a bit more complicated, so I have to expand the original problem a bit. The query has to handle unknown number of departments, and a date...
13
1895
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 this is because in the table i only have the 'standIn' listed by integer and i want to return the 'standIn' by name. I hope this is clear enough.
3
1732
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 not always the correct 'NextActionDate'/'NextStatus'/'NextState'. I'm sure I'm missing something easy, but I can't figure out what it might be. ...
14
4280
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 salvage the records from the many table and without going into detail, one of the reasons I can't do the opposite as there are records in the ONE table...
16
16993
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 must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then...
10
4563
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 precisely, it updates that table to change the search_path temporarily). With the postgres 7.3 (and 7.4 too) installed on my debian development...
13
4216
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 solution here - until now. This one is driving me crazy. I am making my first attempt at creating a runtime application. I am using Access 2003...
3
3717
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 in the application, but I'd rather not! DDL for table and trigger below. TIA
6
2178
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 be aligned on the ESPI common columns. In this attached image, the first lines ESPI of 010471 "ADJUSTABILITY" which should line up with the...
2
4960
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 still not working correctly. Here is my code: create trigger emp_update_id BEFORE update on emp_update REFERENCING NEW AS N for each row SET...
0
7814
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8109
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6471
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5316
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3752
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2253
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1356
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1072
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.