Chapter 1: X++ Unit Test Framework
Chapter 2: Working with Data
Chapter 3: Classes
Chapter 4: Forms
Chapter 5: Visual Studio Integration
Chapter 6: Workflow
Lesson 6 : Computed Columns in Views
Computed Columns in Views
A view is a selected number of fields that come from one or more related tables. Microsoft Dynamics AX can also display a computed column based on fields in those tables. A computed column generates T–SQL code at compile time and adds it to the T–SQL code generated by the view, which increases performance.
This walkthrough describes how you can add a computed column to a view in Microsoft Dynamics AX.
A computed column is the output of a computation that inputs a regular column. For example, suppose your table has a column that is named AnnualRent. Your view could return that is named MonthlyRent and which calculates AnnualRent/12.
You can add the computed column to the select list of columns only. If the computed column is itself a select statement with a where clause, you can include the name of a real column in that where clause.
To fully understand this walkthrough you must know how to do the following:
- How to use the Application Object Tree (AOT).
- How to write an method in X++.
This topic also explains how you can add a computed column to a union view in Microsoft Dynamics AX. When a T-SQL union is involved, the support method that generates the T-SQL code for the computed column must input an int parameter. The parameter specifies one particular branch of the union query of the view. The T-SQL code that the method must output often differs depending on the branch.
This walkthrough illustrates the following tasks:
- Create a union query.
- Create the view with regular columns.
- Add a computed column to the union view.
- Examine the T-SQL code that is generated for the view.