473,738 Members | 11,192 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ptComp lete = -1
WHERE 4ptTable.ptKey = 5vTable.vptKey And 5vTable.vComple te = -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 2629
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******@googl email.comwrote in message
news:11******** **************@ m79g2000cwm.goo glegroups.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.ptComp lete = -1
WHERE 4ptTable.ptKey = 5vTable.vptKey And 5vTable.vComple te = -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
248475
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 particular surname in a particular town. I can select the records fine with this syntax (testing in Oracle SQL* Plus) SELECT NAMEINFO.LASTNAME, NAMEINFO.FIRSTNAME, NAMEINFO.MIDDLENAME, NAMEINFO.GENDER, ADDRESSINFO.REGION FROM NAMEINFO, ADDRESSINFO...
8
89312
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 tblMyTable.UniqueID = tblMyTableTEMP.UniqueID SET tblMyTable.myField = tblMyTableTEMP.myField, tblMyTable.myField2 = tblMyTableTEMP.myField2,
27
2537
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 check these first:- <http://developer.irt.org/script/script.htm>
16
3874
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 table, or perhaps bytes, being updated where the engine just decides, screw it, i'll just make a new one. surfed this group and google, but couldn't find anything. the context: we have some java folk who like to parametize/
3
3449
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 the necessary records in it when testing it. I get the error "No value given for one or more required parameters." when I try to update the database. Can you tell me what am I doing wrong?
9
12986
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 northwind database that has an employees, orders, and order details. the following are the 3 tables in my sql database students schyrsem
7
2481
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 there is changes. thank in advance
5
2597
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
3110
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 havnt tested the index yet ) so you can use an .UPDATE( dataTable ) on the data adapter. Otherwise you will get an exception error. Is this statement true? ---- Now me fumbling thru
3
3965
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
8969
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8788
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9476
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9263
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4570
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
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
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.