|
I have a table that has an employee dependent relationship.
Table columns:
MbrID
key1
isDependent
StartDate
EndDate
Status
Name
Example Data:
123 blue N 01/01/2023 12/31/2023 E Sam Smith
123 blue N 01/01/2024 12/31/2024 X Sam Smith
123 blue Y 01/01/2023 12/31/2023 Olivia Smith
123 blue Y 01/01/2024 12/31/2024 Olivia Smith
789 blue N 01/01/2023 12/31/2023 E Ken Jones
789 red N 01/01/2024 12/31/2024 X Ken Jones
789 blue Y 01/01/2023 12/31/2023 Bob Jones
789 red Y 01/01/2024 12/31/2024 Bob Jones
I need to update the dependents with the related employee status. end
result looking like.
Example Date after update:
123 blue N 01/01/2023 12/31/2023 E Sam Smith
123 blue N 01/01/2024 12/31/2024 X Sam Smith
123 blue Y 01/01/2023 12/31/2023 E Olivia Smith
123 blue Y 01/01/2024 12/31/2024 X Olivia Smith
789 blue N 01/01/2023 12/31/2023 E Ken Jones
789 red N 01/01/2024 12/31/2024 X Ken Jones
789 blue Y 01/01/2023 12/31/2023 E Bob Jones
789 red Y 01/01/2024 12/31/2024 X Bob Jones
I have an sql that looks like it will join the rows together.
select a.mbrid, b.mbrid, a.key1, b.key1, a.isdependent, b.isdependent,
a.status, b.status, a.startdate, b.startdate, a.enddate, b.enddate,
a.name, b.name
from myLib.myTable a
*left* join myLib.myTable b
on a.mbrid = b.mbrid and a.key1 = b.key1 and a.startdate = b.startdate and
a.enddate = b.enddate
Can I get it to do the update to the dependent status column in the same
SQL?
Do I need to do some sort of CTE?
--
Kerwin Crawford
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/midrange-l.
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.