Microsoft Dynamics AX SQL 加入翻译

Microsoft Dynamics AX SQL JOIN Translation

我想知道 Axapta 是如何翻译它的 SQL 语句并遇到这个问题的: how-joins-in-x-select-statement-are-translated-into-t-sql

这是网站上给出的第一个示例。

在 X++ 中加入:

select AccountNum from custTable
    join TaxGroupId from custGroup
    where custGroup.CustGroup == custTable.CustGroup;

T-SQL 中的交叉连接:

SELECT T1.ACCOUNTNUM, T1.RECID, T2.TAXGROUPID, T2.RECID
FROM CUSTTABLE T1 CROSS JOIN CUSTGROUP T2
WHERE ((T1.PARTITION=?) AND (T1.DATAAREAID=?))
  AND (((T2.PARTITION=?) AND (T2.DATAAREAID=?)) 
   AND (T2.CUSTGROUP=T1.CUSTGROUP))

我现在想知道这个语句中的问号是什么意思。 由于语法错误,? 被标记为错误。

WHERE ((T1.PARTITION=?) AND (T1.DATAAREAID=?)) 是什么意思?

这些字段是 Dynamics AX 中数据隔离实施的一部分。更多信息 here

字段 T1.PARTITION 与分区相关:

Partitions divide and isolate the business data of an installation by using special processing that the AOS applies to data queries. This special processing occurs immediately before the queries are sent to the underlying Microsoft SQL Server database when a system field named Partition is present in a queried table.

字段 T1.DATAAREAID 与公司或法律实体相关:

Each partition contains at least one company or legal entity. A legal entity occurs in only one partition. When you create a legal entity, the system assigns it to the current partition. The legal entity can never be moved to another partition. However, its data can be exported from the partition and then imported to another company in another partition.

问号最终会被 Partitions 和 Companies 的实际值代替,具体取决于调用该语句的上下文。

问号是占位符,使 SQL 服务器能够计算搜索值经常变化的查询的执行计划。

Microsoft Dynamics AX may pass either parameters (placeholders) or literals (actual values) in queries.

• Parameters allow Microsoft Dynamics AX and the database server to reuse the query when search values change. They are preferred for high-frequency queries.

• Literals allow the database server to optimize the query for a specific piece of information. This provides an optimal query for that piece of information, but the database server must perform the optimization for every query executed. Literals may be used for long running queries such as complex joins.

A developer can override the default use of literals by specifying parameters in their code, or an administrator can override the use of literals in the Server Configuration Utility.