473,397 Members | 2,084 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,397 software developers and data experts.

SQL update- where problem

I have a parent record with a child record.

The parent record contains structures and the child records contains
visits to those structures.

Each table has a field named "Complete", what I want is the structure
'complete' to be changed to true when ANY of the visits have been
completed.

I have tried to implement SQL to do this, but it gives me the error
"Syntax Error (Missing Operator)..." when I try and save the query. I
have searched through the forums and couldn't find anything relevent to
this.

My SQL code (the error is on the last line i think):

UPDATE 4ptTable, 5vTable
SET 4ptTable.ptComplete = -1
WHERE 4ptTable.ptKey = 5vTable.vptKey And 5vTable.vComplete = -1

Where 4ptTable is the parent table (structures), 5vTable is the child
table (visits), ptComplete is the field I wish to update (with the
value -1 [true]), ptkey is the primary key and vptKey is the foriegn
keym vComplete is whether the visit is complete.

? Am I right in thinking I need the primary key to be equal to the
foreign key - otherwise it will update all records in the recordset.
? I may also need to change this so that the parent record will change
only when ALL the child records are completed - any ideas.

I'm hoping that it is just my basic SQL code that is wrong...
grr, why can't SQL be as intinctive as VBA!

Cheers,
James Hallam

Aug 1 '06 #1
1 2615
You could probably do it by using a subquery and including the square
brackets around the names that start with a number:

UPDATE [4ptTable] SET [4ptTable].ptComplete = True
WHERE ([4ptTable].ptComplete = False)
AND EXISTS (SELECT vptKey FROM [5vTable]
WHERE ([5vTable].vptKey = [4ptTable.ptKey])
AND ([5vTable].vComplete = True));

However, I question whether the ptComplete field is justified.
If it should *always* be True if any related record is True,
then it is dependent data, and should not be stored.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"James Hallam" <ja******@googlemail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
>I have a parent record with a child record.

The parent record contains structures and the child records contains
visits to those structures.

Each table has a field named "Complete", what I want is the structure
'complete' to be changed to true when ANY of the visits have been
completed.

I have tried to implement SQL to do this, but it gives me the error
"Syntax Error (Missing Operator)..." when I try and save the query. I
have searched through the forums and couldn't find anything relevent to
this.

My SQL code (the error is on the last line i think):

UPDATE 4ptTable, 5vTable
SET 4ptTable.ptComplete = -1
WHERE 4ptTable.ptKey = 5vTable.vptKey And 5vTable.vComplete = -1

Where 4ptTable is the parent table (structures), 5vTable is the child
table (visits), ptComplete is the field I wish to update (with the
value -1 [true]), ptkey is the primary key and vptKey is the foriegn
keym vComplete is whether the visit is complete.

? Am I right in thinking I need the primary key to be equal to the
foreign key - otherwise it will update all records in the recordset.
? I may also need to change this so that the parent record will change
only when ALL the child records are completed - any ideas.

I'm hoping that it is just my basic SQL code that is wrong...
grr, why can't SQL be as intinctive as VBA!

Cheers,
James Hallam

Aug 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
27
by: VK | last post by:
<http://www.jibbering.com/faq/#FAQ3_2> The parts where update, replacement or add-on is needed are in <update> tag. 3.2 What online resources are available? Javascript FAQ sites, please...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
9
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from...
7
by: jaYPee | last post by:
I am having a problem on how to update view from sql server 2000 database. I have tried dataset and sql dataadapter but no luck. I'm using this view in datagrid and i want to update the datagrid if...
5
by: Stephen Plotnick | last post by:
I'm very new to VB.NET 2003 Here is what I have accomplished: MainSelectForm - Selects an item In a public class I pass a DataViewRow to ItemInformation1 Form ItemInformation2 Form
2
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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,...

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.