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

In Dire need of table manipulation help

69
Hello all.

I have a table in Access that has a check box as one of the fields. I want to write a query or code that will check or uncheck that box based on conditions met by other fields in the table. Here are the specifics as well as I can explain it:

I have the following table fields:

EmployerID
Group
Payroll
Yes/No

In the table I will have multiple instances of an EmployerID, one for each Group. Then there can be a monetary number in the Payroll field (or it can be 0). And the Yes/No field is the check box.

What I want to do is evaluate each group of records based on EmployerID.

If a given EmployerID has all ZEROs in the Payroll field for each Group I want to set the Yes/No to Yes(checked) for each record with that EmployerID.

If even one Payroll field for a given EmployerID has a value greater than ZERO I want to set the Yes/No to No(unchecked) for each record with that EmployerID (even those that have a ZERO Payroll).

I hope this makes sense. I don't care if it's done in a query or a module, as long as it works.

Any help will be greatly appreciated!
Thanks,
narpet
Nov 7 '06 #1
8 2154
MMcCarthy
14,534 Expert Mod 8TB
Hello all.

I have a table in Access that has a check box as one of the fields. I want to write a query or code that will check or uncheck that box based on conditions met by other fields in the table. Here are the specifics as well as I can explain it:

I have the following table fields:

EmployerID
Group
Payroll
Yes/No

In the table I will have multiple instances of an EmployerID, one for each Group.
Is your tables primary key EmployerID and Group together?


Then there can be a monetary number in the Payroll field (or it can be 0). And the Yes/No field is the check box.

What I want to do is evaluate each group of records based on EmployerID.

If a given EmployerID has all ZEROs in the Payroll field for each Group I want to set the Yes/No to Yes(checked) for each record with that EmployerID.
UPDATE TableName SET [Yes/No]="Yes"
WHERE Count(Group) = Count(IIf(Payroll=0,1,0))
AND EmployerID=<some value>;


If even one Payroll field for a given EmployerID has a value greater than ZERO I want to set the Yes/No to No(unchecked) for each record with that EmployerID (even those that have a ZERO Payroll).
Set the default value for [Yes/No] to "No"
Nov 7 '06 #2
narpet
69
Thanks for the help, but I'm not sure if this will work for me because I have to be able to change the Yes/No field without specifying an EmployerID. In other words, it needs to be able to make this change based on Group and EmployerID without calling a specific one...

example records:

EmployerID Group Payroll Yes/No
1 A $10.00
1 B 0
1 C 0
2 A 0
2 B 0
2 C 0

In this example I would want to set all of the Yes/No fields in the records for EmployerID 1 to No because one of those records had money in it.

I would want to set all of the Yes/No fields in the records for EmployerID 2 to Yes because none of those records have money in them.

I need to do it without having to specify EmployerID. There are thousands of records and it's not practical to specify any given criteria.

Any more help will be greatly appreciated.

Thanks,
narpet
Nov 8 '06 #3
Killer42
8,435 Expert 8TB
Ok, despite the "top ten" listing I'm not an Access expert - just a dabbler. My SQL knowledge is at a very simple level.

However, to me it sounds as though you might want an aggregate query grouping records by employee ID, with a count of non-zero payrolls, or a subtotal of payrolls. To that, you should be able to JOIN (don't know which type) based on the count (or subtotal) being zero.

Does this sound reasonable?
Nov 8 '06 #4
NeoPa
32,556 Expert Mod 16PB
It does indeed Killer.
I just finished looking at this question and decided that it's something I can help with - when my brain is a little less tired than it is now.
If I haven't posted a helpful reply by tomorrow night (I hope you can wait that long), then you have my permission to remind me with a PM.
Nov 8 '06 #5
Killer42
8,435 Expert 8TB
...aggregate query grouping records by employee ID, with a count of non-zero payrolls, or a subtotal of payrolls. To that, you should be able to JOIN (don't know which type) based on the count (or subtotal) being zero.
Um... actually, I imagine the "not zero" would have to be applied to the aggregate query before doing the JOIN - help me out here, someone.
Nov 8 '06 #6
NeoPa
32,556 Expert Mod 16PB
I don't know the name of your table so, for my answer, I'm using [tbl]. Replace all occurrences of this with your table name when you use it.

Expand|Select|Wrap|Line Numbers
  1. UPDATE [tbl] INNER JOIN (SELECT [EmployerID], (NOT Max([Payroll])) AS YN
  2. FROM [tbl]
  3. GROUP BY [Group]) AS subYN ON [tbl].[EmployerID] = [subYN].[EmployerID]
  4. SET [tbl].[Yes/No] = [subYN].[YN]
Now, I suspect this may fail with an error message about being an non-updatable recordset.
If that is the case then we are a little stuck and probably have to do something with a temporary table.
I'm afraid I can't test this myself due to not having your data available (or time for that matter) so post back your test results if you would.
Nov 8 '06 #7
narpet
69
You sparked my imagination and I ended up doing it the simple way.

I used a query to create a temporary table to put all the records where the sum of the Payroll for a given EmployerID was 0.

Then I used that temporary table to update the Yes/No field based on the records in the temporary table.

Works like a charm.

Thanks to everyone for the help and ideas.

narpet
Nov 8 '06 #8
Killer42
8,435 Expert 8TB
You sparked my imagination and I ended up doing it the simple way.
If we provided ideas that inspired you to solve the problem for yourself, then that's probably the best result we could hope for. :)

Cheers!
Nov 8 '06 #9

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

Similar topics

2
by: Mike | last post by:
My page populates a table with a list of names and other information from a JavaScript object. I receive changes (adds, change & delete) to that list, convert it into a JavaScript object. I do...
1
by: VK | last post by:
Hello, I am currently doing a project on Access and am current stuck in the "search" process and hoping that you could help me out. I have got 3 tables designed. When the user clicks on search...
5
by: Seth | last post by:
I have one table of the form: Delivery Product 101 A 101 B 101 C 102 A 102 E 103 C 104 A
4
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
0
by: L'eau Prosper Research | last post by:
Press Release: L'eau Prosper Research (Website: http://www.leauprosper.com) releases new TradeStation 8 Add-on - L'eau Prosper Market Manipulation Profiling Tools Set. L'eau Prosper Market...
0
by: L'eau Prosper Research | last post by:
NEW TradeStation 8 Add-on - L'eau Prosper Market Manipulation Profiling Tools Set By L'eau Prosper Research Press Release: L'eau Prosper Research (Website: http://www.leauprosper.com) releases...
5
by: Andrew Hedges | last post by:
Wherein I attempt to debunk some myths about the relative merits of the two methods for programmatically adding content to a web page: ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.