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)

Query in computed column

(0) ShareShare
ReportReport
Posted on by

Hi All

I Read about Computed Column and understood that it's used to do a calculation and have the calculation result as a field in the view.

However, i need to perform a query and return a result as a field in the view. the query that want perform can not be placed as a join in my view.

Can this be achieved using Computed Column ??

Regards.

*This post is locked for comments

I have the same question (0)
  • Brandon Ahmad Profile Picture
    2,465 User Group Leader on at

    Yes, if you write your computed column as a subquery that equivocates to an expression, but be careful.  This often causes bad performance issues if the view is of any reasonable size.  It's almost always better to use a temp table when faced with this scenario.  

  • Walid Gamal Profile Picture
    on at

    Hi Brandon

    Can u give me link for that or an example to understand it

    Regards.

  • Suggested answer
    Brandon Ahmad Profile Picture
    2,465 User Group Leader on at

    Remembering what I said about this particular technique really jacking with performance if the view is of any reasonable size, I'll explain how to do it here.  You have to go outside of the documentation and get your advanced developer on a little bit, but here is how to do it.  Get the definition of your view in SQL Server by right clicking on the view and clicking "View Definition" from management studio.  

    Now, alter your view by adding a subquery within a case expression like here:

    blogs.msdn.microsoft.com/.../subqueries-in-case-expressions

    Make sure that it runs in sql -- that is how you know that it works.  Then copy the syntax only for the case statement with the subquery inside of it.  Create a computed column and put it in the '' (single quotes).  A computed column only expects a string that can fit within a sql statement.  You need to build a string that equals the exact expression in the sql statement that you tested earlier.  You'll know it works because the view will synchronize.  If it doesn't synchronize, it will warn you with the error and you can make changes.  

    Sadly, there is no documentation with an example like this (there are several simpler examples documented though) but I've done it a few times.  Just remember the key is that the string generated is the same that you tried out with direct sql when you tested the view.  

  • Suggested answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    AX2012: Subqueries in views might help you.

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