Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 10th, 2010, 05:10 AM
Authorized User
Join Date: May 2009
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update query doesnt run when Select query does (In MS Access)

In MS Access I am trying to update a field (memo) to equal the previous entry for the memo field plus some text and the value of the AltPhone field when the AltPhone field is not empty. When I run it as a select query I get the answer I want. When I change it to an update query, it does not work. Does anyone know why?

My logic is that I try to set a new field name in the query to be the calculation and then make the memo field update to the contents of this new field.

Memo is in the Customer table, Alt Phone is in the actexcel011610 table. Both tables have an OO field (stands for original order - don't ask) which is the join field.

The SQL version (I created this in the Access query graphical interface) is (and which clearly ignores the defining of the calculation for the MemoCombined field):

UPDATE actexcel011610 INNER JOIN Customer ON actexcel011610.OO = Customer.OO SET Customer.[Memo] = [memoCombined]
WHERE (((actexcel011610.[Alt Phone]) Is Not Null));

In the graphical design section, I define the MemoCombined shows as
MemoCombined: IIf([memo]<>"",[memo] & ", Alt phone is " & [alt phone],"Alt phone is " & [alt phone])

When run as a Select query, the above MemoCombined section runs perfectly, with the SQL code as:

SELECT IIf([memo]<>"",[memo] & ", Alt phone is " & [alt phone],"Alt phone is " & [alt phone]) AS MemoCombined, Customer.Memo, actexcel011610.OO
FROM actexcel011610 INNER JOIN Customer ON actexcel011610.OO = Customer.OO
WHERE (((actexcel011610.[Alt Phone]) Is Not Null));

So I then tried to break it into two steps. First I ran a select query so I got the field of MemoCombined calculated. Then ran what seemed a simpler query based on the select query and the Customer table, trying to change [customer].[memo] to the MemoCombined value. And still it did not work. The SQL on this attempt is:

UPDATE Customer INNER JOIN Set_MemoCombined_Value ON Customer.OO = Set_MemoCombined_Value.OO SET Customer.[Memo] = [memocombined]
WHERE (((Customer.Memo) Is Null));

What am I doing wrong? I am not very skilled in SQL and generally rely on the Access graphical interface to set up my queries.

If it helps, the Memo field currently has only about 10 our of 6000 records with entries. And Alt Phone field has 11 entries.
Old February 10th, 2010, 08:43 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi

HI there..

If the query doesn't run, you probably receive an error. Can you put it here??

Also, it's usually not posible to update query that contains joins. The error is about it???


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
================================================== =========
I know that CVS was evil, and now i got the
================================================== =========
Old February 10th, 2010, 10:48 PM
Friend of Wrox
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts

I don't believe that Access allows you to use a MEMO field like that. See, it's possible to end up needing a buffer bigger than all of memory when you try to UPDATE a MEMO field based on its prior contents.
Old February 11th, 2010, 04:54 AM
Authorized User
Join Date: May 2009
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default What I mean by a memo field

This is not a field of memo type. It is a normal text field that is used to record internal notes (as in memos to self).

Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Access Query neha2007 SQL Language 1 July 12th, 2007 10:11 AM
ms access query umeshtheone VB Databases Basics 1 June 1st, 2007 10:27 AM
MS Access Query rsm42 ASP.NET 1.0 and 1.1 Basics 2 March 20th, 2007 12:32 PM
MS Access Query sunny76 Access 4 October 18th, 2006 06:54 AM
update query doesnt work knight Classic ASP Databases 4 June 10th, 2004 07:24 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.