web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Unable to Convert SQL query in x++ for RDP Class?

(0) ShareShare
ReportReport
Posted on by

Hi Everyone,

I have written a query in SQL (report builder ) and it is working fine but now i want to use this query in x++ RDP class for SSRS.

below is the sql query :

x-----------------------x-------------------------------------------------------x

from hcmworker

inner join DirpartyTable on hcmworker.PERSON = DirpartyTable.RECID
inner join dirPartyLocation on dirPartyTable.RecId = dirPartyLocation.Party
inner join HcmPositionWorkerAssignment on HcmPositionWorkerAssignment.Worker = hcmworker.RECID

inner join HcmPositionDetail on HcmPositionWorkerAssignment.Position=HcmPositionDetail.Position


inner join dimattributeomdepartment on dimattributeomdepartment .RECID=HcmPositionDetail.department


inner join logisticsLocation on dirPartyLocation.Location = logisticsLocation.RecId


inner join hcmemployment on hcmworker.recid=hcmemployment.worker
left outer join  assettable on hcmworker.personnelnumber= assettable.personnelnumber

--and LOGISTICSELECTRONICADDRESS.LOCATOR LIKE '%computers%'






where HcmPositionDetail.VALIDFROM <= getdate()
and HcmPositionDetail.VALIDTO >= getdate()
and hcmemployment.VALIDTO >= getdate()
--and hcmemployment.VALIDFROM >=getdate()

and ASSETTABLE.ASSETID IS NULL
OR assettable.assetgroup='computers'
and HcmPositionDetail.VALIDTO >= getdate()

ORDER BY hcmworker.PERSONNELNUMBER DESC

x-----------------------x-------------------------------------------------------x

Please help me in converting this query into X++.

i got stuck on how to handle getdate() and NULL query.

thank you

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    239,392 Most Valuable Professional on at

    Regarding date-effective data, use validTimeState keyword in the select statement. Look at the documentation - Select Statement Syntax - including comments below it.

    Null values aren't supported in AX. Maybe you want to use a nonexists join instead?

  • Community Member Profile Picture
    on at

    FYI I have started my query with

    while select * from hcmWorker

    and then inner joins

    can you please elaborate how to use validTimeState keyword  to use with  "and HcmPositionDetail.VALIDTO >= getdate()"

    thank you

  • Suggested answer
    Mahmoud Hakim Profile Picture
    17,887 on at

    if you are expert in SQL, you can create a data source in visual studio and create your query with the same syntax as the below

    or as sukrat said "divide your query in RDP"

    87351.2.png

    87351.2.png

    create the report and select data source type "your data source"

    after that click query and write as below 

    4034.3.png

  • Suggested answer
    Martin Dráb Profile Picture
    239,392 Most Valuable Professional on at

    Maqbool, use validTimeState keyword at the top level, i.e. while select validTimeState(...) * from hcmWorker. It should apply to the whole query.

  • Community Member Profile Picture
    on at

    @sukrut Parab Thank you so much for the detail response. Let me try and get back to you

  • Community Member Profile Picture
    on at

    Mahmoud Hakim haha why this idea dont come in the mind. Thank you,

    Actually in that case i have to give rights to the end user (sql read only) to access reports.

  • Community Member Profile Picture
    on at

    Mr. Martin & Sukrut i have modify the query now its look like :

            utcdatetime  validTimeStateFrom = DateTimeUtil::minValue();

    utcdatetime validTimeStateTo= DateTimeUtil::maxValue();

           while select validTimeState(validTimeStateFrom,validTimeStateTo) * from hcmWorker

             where hcmEmployment.Worker == hcmWorker.RecId

               // && hcmEmployment.ValidTo >= DateTimeUtil::utcNow()

                join hcmemployment where  hcmworker.recid==hcmemployment.worker

               join DirpartyTable where hcmWorker.PERSON == dirpartyTable.RECID  

     join dirPartyLocation  where dirPartyTable.RecId == dirPartyLocation.Party                

               join HcmPositionWorkerAssignment where hcmPositionWorkerAssignment.Worker== hcmWorker.RECID

               join hcmemployment where  hcmWorker.recid==hcmEmployment.worker

    but still not working ,

    thank you

  • Martin Dráb Profile Picture
    239,392 Most Valuable Professional on at

    Could you describe the problem, please? I have no solution for "not working".

    Also, I thought you wanted to limit ValidTo, so it's not clear to me why you're using DateTimeUtil::maxValue().

  • Community Member Profile Picture
    on at

    My problem is that i want to generate a list of Active workers with having Personnel Number, Name, Position and Department fields on the report.i achieved this in SQL but unable to do in X++.

    FYI not working means not generating data on the report.

    now please resolve it. :P : )

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans