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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Select first five, select in random order

(0) ShareShare
ReportReport
Posted on by 30

Dear All,

Suppose i have one table say StudentDetails.
It's having 30 records with Student ID and Name.
Student ID : S01,S02,S03,S04,S05,S06,S07,S08,S09 etc

I have 2 queries

1. I want to return first 5 records only.
     Is there any function in AX OR I have to write while select with for loop?

2. I want to return randomly Student ID like S02,S05,S08 with using while select.
    How to acheive this.
    Could you please give more shed on this.

Thanks!

Arpan

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    1) You could use a counter in a while select and use if (counter == 5) break;

    2) There is no such thing for a relational database as "random", it is always ordered by some columns (at least by cluster index).

  • @rp@n Profile Picture
    30 on at

    Thanks Vilmos

  • Verified answer
    Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    If you consult the select statement syntax (as you always should if you're in doubt), you'll find that it supports firstOnly and firstOnly10, but no firstOnly5. Therefore you can use a while select with firstOnly10 and break the loop as explained by Vilmos.

    Regarding random order, consider getting IDs as usual, putting them to an array and using Random class to get random indexes. Alternatively (especially if there are many records), you can create a view with a computed column based on RAND() function.

  • @rp@n Profile Picture
    30 on at

    Thanks Martin

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi @rp@n ,

    please look into my blog it is may useful to you future.

     

    http://axsuresh.blogspot.in/2016_05_01_archive.html

     

    Thanks,

  • @rp@n Profile Picture
    30 on at

    Thanks Suresh

  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    The link shows just "No posts" message to me. Could fix the link and provide a description of what's there, so people can find the solution here even if the linked site doesn't work?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans