简体   繁体   中英

Dynamics AX 2012 Subquery in a View

AX allows you to enter basic SQL into View ranges. For example, in an AOT view's range, for the match value, you could enter (StatRepInterval.Name == 'Weekly'). This works nicely.

However, I need to do a more advanced lookup on a View, using a subquery. Can anyone suggest a way to do this?

This is what I would like to use, but I receive an error: "Query extended range failure: Syntax error near 34."

(StatRepInterval.Name == (SELECT FIRSTONLY StatRepInterval.Name FROM StatRepInterval WHERE StatRepInterval.PrintDirection == 1 ORDER BY StatRepInterval.Name DESC))

I've tried a lot of different variants of the subquery, from straight T-SQL to X++ SQL, but nothing seems to work.

Thanks for the help.

Sub-queries are not supported in query expressions.

This may be solved by using additional datasources with inner or outer joins as you observed.

See the spec and Axaptapedida on query expressions.

I found a way to do this. It isn't pretty, and I'm going to leave the question unanswered for a bit, should someone else have a more graceful solution.

  1. Create a source View that contains all fields I wish to return, plus calculated fields that contain my subquery results.

  2. Create a second View that uses the first as a data source, and applies all the necessary ranges.

Works pretty nicely.

Probably inefficient if there were large tables of data, but this is in a relatively small section of AX.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM