Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

how can i select only duplicate in the statement select

Posted on by 2,016

greeting everyone

i'm already created report but in my report i need only to appearance the duplicate depending on column 

here in my code need only the duplicated workers depend on personal number

while select hcmPositionWorkerAssignment where hcmPositionWorkerAssignment.Worker==hcmWorkerRecId
            && ( (hcmPositionWorkerAssignment.ValidFrom >= fromDate) && (hcmPositionWorkerAssignment.ValidFrom <= toDate) )
        {
            TransferEmpReportTemp.clear();
            TransferEmpReportTemp.PersonnelNumber=hcmWorker::find(hcmPositionWorkerAssignment.Worker).PersonnelNumber;
            TransferEmpReportTemp.WorkerName=hcmWorker::find(hcmPositionWorkerAssignment.Worker).name();
            TransferEmpReportTemp.Position=hcmPosition::find(hcmPositionWorkerAssignment.Position).description();
            TransferEmpReportTemp.ValidFrom=hcmPositionWorkerAssignment.ValidFrom;
            TransferEmpReportTemp.ValidTo=hcmPositionWorkerAssignment.ValidTo;

            select * from hcmPosition where hcmPosition.RecId==hcmPositionWorkerAssignment.Position;

            select * from hcmPositionDetail
         where hcmPositionDetail.Position==hcmPosition.RecId;

            select * from oMOperatingUnit
        where oMOperatingUnit.RecId==hcmPositionDetail.Department;
        TransferEmpReportTemp.Department=oMOperatingUnit.Name;

            select PaidByLegalEntity from payrollPositionDetails
        where hcmPositionWorkerAssignment.Position==payrollPositionDetails.Position;

            select DataArea from companyInfo
        where payrollPositionDetails.PaidByLegalEntity==companyInfo.RecID;

            TransferEmpReportTemp.Company=companyInfo.Name;

            TransferEmpReportTemp.insert();
        }

mean if the personal number has been duplicated show them only if not duplicated don't show them

the idea of my report is giving me all workers which have more than position whatever if he in current or already terminate 

  • mohammed.mqi Profile Picture
    mohammed.mqi 2,016 on at
    RE: how can i select only duplicate in the statement select

    ok i solve it by using group thanks was so usefully

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: how can i select only duplicate in the statement select

    There is even a more efficient way. Just using group by means that you would still have to load and iterate all personnel numbers, even those that are not duplicate (which will be the vast majority, I assume). The condition can be moved to DB server and then load only those personnel numbers that occurs more than once. Please refer to Walkthrough: Creating an AOT Query that has Group By and Having Nodes.

    Nevertheless there is unique index on Person+PersonnelNumber, therefore there can't be two persons with the same PersonnelNumber. I wonder what actual problem you're trying to address.

  • Suggested answer
    Hariharans87 Profile Picture
    Hariharans87 4,971 on at
    RE: how can i select only duplicate in the statement select

    In SQL, there is a Having clause for aggregate functions condition and Distinct count. We can use both to check the duplicate or more than one records.

    In X++, we don't have having and discount count. So, we can use group by and inside need to use if condition like

       while select count(RecId) from purchLine

           group by purchLine.ItemId

       {

           if(purchLine.RecId > 10)

           {

           ....

           }

       }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans