Login
Register
Search
Home
Forums
Jobs
LawsonGuru
LawsonGuru Letter
LawsonGuru Blog
Worthwhile Reading
Infor Lawson News Feed
Store
Store FAQs
About
Forums
Human Capital Management
Lawson S3 HR/Payroll/Benefits
Combining multiple records into one using SQL
Home
Forums
Jobs
LawsonGuru
LawsonGuru Letter
LawsonGuru Blog
Worthwhile Reading
Infor Lawson News Feed
Store
Store FAQs
About
Who's On?
Membership:
Latest:
Saef
Past 24 Hours:
0
Prev. 24 Hours:
0
Overall:
5226
People Online:
Visitors:
195
Members:
0
Total:
195
Online Now:
New Topics
S3 Systems Administration
ADFS certificate - new cert
12/3/2024 9:38 PM
The certificates on the windows boxes expired and
Lawson S3 HR/Payroll/Benefits
Post Tax Benefit Plan Table
11/14/2024 9:16 PM
Hi, totally new to Laswon. I have a repor
Lawson S3 Procurement
ED501 Error: Map 850 not supported by /law/c15vda/lawson/test10/edi/bin/laws_out_91
11/12/2024 3:47 PM
Tried runnning ED501 and getting the atathced erro
Lawson S3 HR/Payroll/Benefits
Error
11/6/2024 9:54 PM
When I try to enroll a retiree in 72.1 health plan
Infor ERP (Syteline)
Syteline: New Data Maintenance Wizard (Error) Need help
11/1/2024 4:24 PM
Hi, I need help with an error on syteline while us
Dealing with Lawson / Infor
Implementing Lawson v10 with Cerner Surginet, Case Cart Picking, and Quick Adds for the OR
10/29/2024 4:20 PM
Hi Everyone, I am wondering if there is any org
Lawson S3 HR/Payroll/Benefits
Canada Tax Calculation (Federal and Provincial) Issue
10/23/2024 5:00 AM
Initially, we had problem with CPP2 calculation is
Lawson S3 HR/Payroll/Benefits
CA Section 125 401k Plan
10/22/2024 10:13 PM
Does anyone have any recommendations on how to fac
S3 Systems Administration
Running AC120 deleted records from ACMASTER table
10/22/2024 3:40 PM
We recently ran the AC120 as normal and somehow it
Lawson S3 Procurement
RQ13 Approval Info
10/17/2024 2:12 PM
When a Requisition is approved on RQ13, what table
Top Forum Posters
Name
Points
Greg Moeller
4184
David Williams
3349
JonA
3291
Kat V
2984
Woozy
1973
Jimmy Chiu
1883
Kwane McNeal
1437
Ragu Raghavan
1372
Roger French
1315
mark.cook
1244
Forums
Filtered Topics
Unanswered
Unresolved
Announcements
Active Topics
Most Liked
Most Replies
Search Forums
Search
Advanced Search
Topics
Posts
Prev
Next
Forums
Human Capital Management
Lawson S3 HR/Payroll/Benefits
Combining multiple records into one using SQL
Please
login
to post a reply.
4 Replies
1
Subscribed to this topic
68 Subscribed to this forum
Sort:
Oldest First
Most Recent First
Author
Messages
Leonard Courchaine
Veteran Member
Posts: 55
4/14/2010 11:44 AM
We're trying to write a SQL statement that will take multiple rows of data (in this case, emergency contact data from the PAEMERGCNT table) and combine that into 1 record per employee. As you may know, in that table, there can be multiple records (many emergency contacts) for each employee. For an interface we're doing, we need to get all the emergency contacts into one record with the fields like contact1fname, contact1lname, contact2fname, contact2lname, etc.,.
Any ideas on how to do that using SQL?
Thanks very much,
Lenny
Miki M
New Member
Posts: 2
4/14/2010 12:45 PM
This is an example of how I did it for the PAEMPPOS info. You could do the same thing with the contact table using the SEQ_NBR instead of the pos_level. We have a maximum of 5 positions per employee so I've done 5 sections. You would need to determine your maximum number of emergency contacts. I'm sure there is a sharper way to do it, my SQL skills are limited! Hope this helps.
-- Pull all active positions by employee into one row.
select
employee
--Pos 1
,max(case when pos_level = '1' then POSITION end) Pos1
,max(case when pos_level = '1' then POS_LEVEL end) PosLvl1
,max(case when pos_level = '1' then FTE end) FTE1
,max(case when pos_level = '1' then EFFECT_DATE end) EffDt1
,max(case when pos_level = '1' then POS_EFF_DT end) PosEffDt1
,max(case when pos_level = '1' then JOB_CODE end) Job1
,max(case when pos_level = '1' then PROCESS_LEVEL end) PL1
,max(case when pos_level = '1' then DEPARTMENT end) Dept1
,max(case when pos_level = '1' then EXP_ACCT_UNIT end) AcctUnit1
,max(case when pos_level = '1' then SCHEDULE end) Sched1
,max(case when pos_level = '1' then LOCAT_CODE end) Loc1
,max(case when pos_level = '1' then WORK_SCHED end) Work_Sched1
,max(case when pos_level = '1' then USER_LEVEL end) UL1
,max(case when pos_level = '1' then SUPERVISOR end) Supv1
,max(case when pos_level = '1' then SUPERVISOR_IND end) Supv_Ind1
,max(case when pos_level = '1' then PAY_RATE end) Rate1
,max(case when pos_level = '1' then PAY_GRADE end) Grade1
,max(case when pos_level = '1' then PAY_STEP end) Step1
,max(case when pos_level = '1' then ANNUAL_HOURS end) Hours1
--Pos2
,max(case when pos_level = '2' then POSITION end) Pos2
,max(case when pos_level = '2' then POS_LEVEL end) PosLvl2
,max(case when pos_level = '2' then FTE end) FTE2
,max(case when pos_level = '2' then EFFECT_DATE end) EffDt2
,max(case when pos_level = '2' then POS_EFF_DT end) PosEffDt2
,max(case when pos_level = '2' then JOB_CODE end) Job2
,max(case when pos_level = '2' then PROCESS_LEVEL end) PL2
,max(case when pos_level = '2' then DEPARTMENT end) Dept2
,max(case when pos_level = '2' then EXP_ACCT_UNIT end) AcctUnit2
,max(case when pos_level = '2' then SCHEDULE end) Sched2
,max(case when pos_level = '2' then LOCAT_CODE end) Loc2
,max(case when pos_level = '2' then WORK_SCHED end) Work_Sched2
,max(case when pos_level = '2' then USER_LEVEL end) UL2
,max(case when pos_level = '2' then SUPERVISOR end) Supv2
,max(case when pos_level = '2' then SUPERVISOR_IND end) Supv_Ind2
,max(case when pos_level = '2' then PAY_RATE end) Rate2
,max(case when pos_level = '2' then PAY_GRADE end) Grade2
,max(case when pos_level = '2' then PAY_STEP end) Step2
,max(case when pos_level = '2' then ANNUAL_HOURS end) Hours2
----Pos3
,max(case when pos_level = '3' then POSITION end) Pos3
,max(case when pos_level = '3' then POS_LEVEL end) PosLvl3
,max(case when pos_level = '3' then FTE end) FTE3
,max(case when pos_level = '3' then EFFECT_DATE end) EffDt3
,max(case when pos_level = '3' then POS_EFF_DT end) PosEffDt3
,max(case when pos_level = '3' then JOB_CODE end) Job3
,max(case when pos_level = '3' then PROCESS_LEVEL end) PL3
,max(case when pos_level = '3' then DEPARTMENT end) Dept3
,max(case when pos_level = '3' then EXP_ACCT_UNIT end) AcctUnit3
,max(case when pos_level = '3' then SCHEDULE end) Sched3
,max(case when pos_level = '3' then LOCAT_CODE end) Loc3
,max(case when pos_level = '3' then WORK_SCHED end) Work_Sched3
,max(case when pos_level = '3' then USER_LEVEL end) UL3
,max(case when pos_level = '3' then SUPERVISOR end) Supv3
,max(case when pos_level = '3' then SUPERVISOR_IND end) Supv_Ind3
,max(case when pos_level = '3' then PAY_RATE end) Rate3
,max(case when pos_level = '3' then PAY_GRADE end) Grade3
,max(case when pos_level = '3' then PAY_STEP end) Step3
,max(case when pos_level = '3' then ANNUAL_HOURS end) Hours3
--Pos4
,max(case when pos_level = '4' then POSITION end) Pos4
,max(case when pos_level = '4' then POS_LEVEL end) PosLvl4
,max(case when pos_level = '4' then FTE end) FTE4
,max(case when pos_level = '4' then EFFECT_DATE end) EffDt4
,max(case when pos_level = '4' then POS_EFF_DT end) PosEffDt4
,max(case when pos_level = '4' then JOB_CODE end) Job4
,max(case when pos_level = '4' then PROCESS_LEVEL end) PL4
,max(case when pos_level = '4' then DEPARTMENT end) Dept4
,max(case when pos_level = '4' then EXP_ACCT_UNIT end) AcctUnit4
,max(case when pos_level = '4' then SCHEDULE end) Sched4
,max(case when pos_level = '4' then LOCAT_CODE end) Loc4
,max(case when pos_level = '4' then WORK_SCHED end) Work_Sched4
,max(case when pos_level = '4' then USER_LEVEL end) UL4
,max(case when pos_level = '4' then SUPERVISOR end) Supv4
,max(case when pos_level = '4' then SUPERVISOR_IND end) Supv_Ind4
,max(case when pos_level = '4' then PAY_RATE end) Rate4
,max(case when pos_level = '4' then PAY_GRADE end) Grade4
,max(case when pos_level = '4' then PAY_STEP end) Step4
,max(case when pos_level = '4' then ANNUAL_HOURS end) Hours4
--Pos5
,max(case when pos_level = '5' then POSITION end) Pos5
,max(case when pos_level = '5' then POS_LEVEL end) PosLvl5
,max(case when pos_level = '5' then FTE end) FTE5
,max(case when pos_level = '5' then EFFECT_DATE end) EffDt5
,max(case when pos_level = '5' then POS_EFF_DT end) PosEffDt5
,max(case when pos_level = '5' then JOB_CODE end) Job5
,max(case when pos_level = '5' then PROCESS_LEVEL end) PL5
,max(case when pos_level = '5' then DEPARTMENT end) Dept5
,max(case when pos_level = '5' then EXP_ACCT_UNIT end) AcctUnit5
,max(case when pos_level = '5' then SCHEDULE end) Sched5
,max(case when pos_level = '5' then LOCAT_CODE end) Loc5
,max(case when pos_level = '5' then WORK_SCHED end) Work_Sched5
,max(case when pos_level = '5' then USER_LEVEL end) UL5
,max(case when pos_level = '5' then SUPERVISOR end) Supv5
,max(case when pos_level = '5' then SUPERVISOR_IND end) Supv_Ind5
,max(case when pos_level = '5' then PAY_RATE end) Rate5
,max(case when pos_level = '5' then PAY_GRADE end) Grade5
,max(case when pos_level = '5' then PAY_STEP end) Step5
,max(case when pos_level = '5' then ANNUAL_HOURS end) Hours5
from paemppos PA where
end_date = TO_DATE ('01-JAN-1700', 'DD-MON-YYYY')
group by
employee
Leonard Courchaine
Veteran Member
Posts: 55
4/14/2010 1:01 PM
Thanks very much, Miki. My SQL skills are also limited. I didn't want to make my original note too long so I left out the fact that I've used your method but, unfortunately, because of the way the seq_nbr is utilized in paemergcnt, it's ugly. It looks like the seq_nbr keeps incrementing so that I have one employee, for example, whose records use up seq_nbr 4, 6, 8 and 9 (no doubt due to changes/additions/deletions of contacts over time). So, I have this going up to 10 contacts so these are covered. It ends up being long and ugly so that what I end up sending to the other system is 10 instances of emergency contacts with, for most, only 1 used. I was thinking there must be a better way. Thanks again for your input.
Jay Riddle
Veteran Member
Posts: 191
4/14/2010 1:42 PM
Here is an idea on how to do it. I have it do up to three but you may take it as far as you want.
SELECT LTRIM(RTRIM(c1.FIRST_NAME)) + ' ' + LTRIM(RTRIM(c1.LAST_NAME)) AS FULL_NAME1
, c1.HM_PHONE_NBR
, c1.WK_PHONE_NBR
,LTRIM(RTRIM(c2.FIRST_NAME)) + ' ' + LTRIM(RTRIM(c2.LAST_NAME)) AS FULL_NAME2
, c2.HM_PHONE_NBR
, c2.WK_PHONE_NBR
,LTRIM(RTRIM(c3.FIRST_NAME)) + ' ' + LTRIM(RTRIM(c3.LAST_NAME)) AS FULL_NAME3
, c3.HM_PHONE_NBR
, c3.WK_PHONE_NBR
FROM PAEMERGCNT c1
LEFT OUTER JOIN PAEMERGCNT c2
ON c1.COMPANY = c2.COMPANY
AND c1.EMPLOYEE = c2.EMPLOYEE
AND c1.SEQ_NBR <> c2.SEQ_NBR
AND c2.SEQ_NBR =
(
SELECT MIN(SEQ_NBR)
FROM PAEMERGCNT c_next
WHERE c_next.COMPANY = c2.COMPANY
AND c_next.EMPLOYEE = c2.EMPLOYEE
AND c_next.SEQ_NBR <> c1.SEQ_NBR
)
LEFT OUTER JOIN PAEMERGCNT c3
ON c1.COMPANY = c3.COMPANY
AND c1.EMPLOYEE = c3.EMPLOYEE
AND c1.SEQ_NBR <> c2.SEQ_NBR
AND c2.SEQ_NBR <> c3.SEQ_NBR
AND c3.SEQ_NBR =
(
SELECT MIN(SEQ_NBR)
FROM PAEMERGCNT c_next
WHERE c_next.COMPANY = c2.COMPANY
AND c_next.EMPLOYEE = c2.EMPLOYEE
AND c_next.SEQ_NBR <> c1.SEQ_NBR
AND c_next.SEQ_NBR <> c2.SEQ_NBR
)
WHERE c1.SEQ_NBR =
(
SELECT MIN(SEQ_NBR)
FROM PAEMERGCNT c_min
WHERE c_min.COMPANY = c1.COMPANY
AND c_min.EMPLOYEE = c1.EMPLOYEE
)
John Henley
Posts: 3353
4/14/2010 2:01 PM
Depending on your backend db, there are various ways in SQL to create this using pivots. =
Please
login
to post a reply.