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)

ROW_NUMBER() function for computed Columns in View

(0) ShareShare
ReportReport
Posted on by 4,624

Hi, 

I was trying to use of ROW_NUMBER() functions by creating a view as showing below:

4201.Row.PNG

The view shows Row number as irregular . What it should have to ?

looking for your comments on this.

*This post is locked for comments

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

    What's the code of your test() method? What if you actually sort the result by RowNum?

  • Rohin Profile Picture
    4,624 on at
    Public static server str test()
    {
        return 'ROW_NUMBER() OVER ( ORDER BY InvoiceAccount)';
    }

    this is the test() code , Martin.

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

    It's because you generate ROW_NUMBER() across all companies but then you see data just for the current company.

    It seems you actually want something like this:

    ROW_NUMBER() OVER (PARTITION BY Partition, DataAreaId ORDER BY InvoiceAccount)


    Of course, you shouldn't use field names hard-coded as text in production code and you should add table identifier, so it works even if the query consists of several tables.

  • Rohin Profile Picture
    4,624 on at

    Many Thanks Martin, I don't understand one thing why we put all code inside '' . I tested by removing the '' , now its giving me error :The method ROW_NUMBER has not been declared.

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

    It's not X++ code at all; it surely can't compile.

    You said in the other thread that you understand computed columns, but let me repeat what they are. The method returns a piece of T-SQL code as string (usually not written directly as in the example but using helper methods such as DictView.computedColumnString()). This string is then inserted into the view definition and interpreted by SQL Server.

  • Rohin Profile Picture
    4,624 on at

    Got that. Many thanks Martin!!

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans