473,394 Members | 1,742 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,394 software developers and data experts.

A2k - updating Many side dependant on change to record on the One side

Hi,

I have a quick problem that I think I know how to solve using DAO but just
realised an update query would be more elegant. However I don't have a clue
how to implement it.

My main table contains employee records.
Each employee *may* have more than one contract i.e if they do more than one
job. The contract records are in tblContracts.

There is a checkbox on the form (which is bound to tblContracts) to indicate
whether an employee is in the pension scheme.

Now if I have an employee who has 2 or more contracts, I would like the
yes/no value for each of these records to be changed to Yes.
At the moment checking the box only changes the current record.

I'm trying to google the answer but this time I'm not sure what to look
for...

thanks again for any help,
Martin
Nov 12 '05 #1
5 1650
Bleeding hell, i just realised the subject header is all wrong!

I'm not doing anything to the main table, just the tblContracts table.

Nov 12 '05 #2
I could only do it using 2 queries... (Hey, I'm not Joe Celko!)

Find all the Employees with more than one Contract:

"qryMultipleContracts"
SELECT tblEmployee.EmployeeID, Count(tblContract.ContractID) AS
CountOfContractID
FROM tblEmployee INNER JOIN tblContract ON tblEmployee.EmployeeID =
tblContract.EmployeeID
GROUP BY tblEmployee.EmployeeID
HAVING (((Count(tblContract.ContractID))>1));

Mark all these folks...
UPDATE tblEmployee SET tblEmployee.InPensionPlan = True
WHERE (((tblEmployee.EmployeeID) In (SELECT EmployeeID FROM
qryMultipleContracts)));

I tried an inner join on the second one... no dice. I guess that's
why I'm a poor student instead of a rich developer... oh well!
Nov 12 '05 #3
Pieter Linden wrote:
I could only do it using 2 queries... (Hey, I'm not Joe Celko!)

Find all the Employees with more than one Contract:

"qryMultipleContracts"
SELECT tblEmployee.EmployeeID, Count(tblContract.ContractID) AS
CountOfContractID
FROM tblEmployee INNER JOIN tblContract ON tblEmployee.EmployeeID =
tblContract.EmployeeID
GROUP BY tblEmployee.EmployeeID
HAVING (((Count(tblContract.ContractID))>1));

Mark all these folks...
UPDATE tblEmployee SET tblEmployee.InPensionPlan = True
WHERE (((tblEmployee.EmployeeID) In (SELECT EmployeeID FROM
qryMultipleContracts)));

I tried an inner join on the second one... no dice. I guess that's
why I'm a poor student instead of a rich developer... oh well!


Thanks Pieter, I'll be having a go at that later and will report back.
Nov 12 '05 #4
>> My main table contains employee records [sic]. Each employee *may*
have more than one contract i.e if they do more than one job. The
contract records are in tblContracts. <<

Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in
your schema are. Sample data is also a good ideas, along with clear
specifications.

Rows are not records and the differences are important. Next, stop
using those silly, dangerously redudant "tbl-" prefixes; this is
supposed to be SQL and we are supposed to follow ISO-11179 rules for
data element names.
There is a checkbox on the form (which is bound to tblContracts) to indicate
whether an employee is in the pension scheme. <<

So a pension is an attribute of a contract, not an employee ...
Now if I have an employee who has 2 or more contracts, I would like

the
yes/no value for each of these records [sic]to be changed to Yes. <<

CREATE TABLE Personnel
(ssn CHAR(9) NOT NULL PRIMARY KEY,
...);

CREATE TABLE Contracts
(contract_id INTEGER NOT NULL PRIMARY KEY,
ssn CHAR(9) NOT NULL
REFERENCES Personnel(ssn)
ON DELETE CASCADE
ON UPDATE CASCADE,
contract_type CHAR(1) DEFAULT 'N' NOT NULL
CHECK(contract_type IN ('P', 'N', 'T')) -- p = pension
...);

UPDATE Contracts
SET contract_type = 'P'
WHERE ssn
IN (SELECT ssn
FROM Contracts
GROUP BY ssn
HAVING COUNT(contract_id) > 1);

Bu this is a bad data model; pensions should be in the employee data,
not in contracts.
Nov 12 '05 #5
--CELKO-- wrote:
My main table contains employee records [sic]. Each employee *may*
have more than one contract i.e if they do more than one job. The
contract records are in tblContracts. <<

Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in
your schema are. Sample data is also a good ideas, along with clear
specifications.


Blimey, where did you come from. Thanks for the crash course in how to post
to cdm. I've managed ok up to now. I post as much info as is needed but I
think it's important not to overdo it. My SQL is so bad anyway that I'm not
going to convey much in that respect anyhow.
I'm the sort of person who appreciates ideas and concepts that will set me
on my way, I don't often need a specific solution (though it is welcomed
:) )

Rows are not records and the differences are important. Next, stop
using those silly, dangerously redudant "tbl-" prefixes; this is
supposed to be SQL and we are supposed to follow ISO-11179 rules for
data element names.
Get a life mate, i'll keep using my precious tbl prefixes - no one else
seems to object.

<SQL snipped>
Bu this is a bad data model; pensions should be in the employee data,
not in contracts.


I agree with you there but that's what i'm faced with.
Nov 12 '05 #6

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

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
3
by: CSDunn | last post by:
Hello, I have an Access 2000 Project in which the data comes from a SQL Server 2000 database, and multiple users need to be able to see new records as each user adds records. The users also need...
3
by: MLH | last post by:
I have a form, bound to a query. Its RecordSource property is a query named frmEnterLienAmounts. The form has a few bound controls and some unbound controls. The unbound controls are calculated...
4
by: Darrel | last post by:
I'm creating a table that contains multiple records pulled out of the database. I'm building the table myself and passing it to the page since the table needs to be fairly customized (ie, a...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
1
by: ScottL | last post by:
Hello, I have a asp.net Visual Basic web solution with 3 projects: A user interface project (ProjectUI), a Business Object Layer project (ProjectBOL) and a Data Access Layer Project...
14
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
3
by: Asaf | last post by:
Hi, I have a MSSQL 2005 test DB with two tables: Table "T1Customers": T1CustomersRowEnum (PK, int, Not Null) T1CustomersFullName (nvarchar(50) null) Table "T2Details":
33
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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
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
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.