不返回正确计数的x ++脚本 [英] x++ script that do not return correct count
问题描述
我有一个x ++脚本,旨在对来自选择查询的记录进行计数,然后在以后进行更新.
I have a x++ script which aims to count records from a select query and later on be updated.
This is the original question for reference: convert SQL Query with Join to X++ Dynamics AX scripting
最初,我有一个SQL Query副本,它的结果是50行/记录,当我将其转换为X ++时,它没有计数或提取相同数量的记录,
Initially, I have a SQL Query counterpart of it and it is resulting to 50 rows / records, when I convert it to X++ , it is not counting or extracting the same number of records,
这是x ++脚本
static void Job(Args _args)
{
Table1 table1;
Table2 table2;
Table3 table3;
Table4 table4;
Table5 table5;
int i = 0;
while select forUpdate table1
join table2 where table1.field1 == table2.field1
join table3 where table1.field2 == table3.field2
join table4 where table3.field3 == table4.field3
join table5 where table3.category == table5.recid
&& table1.location == 'asia' && table2.modtye == 2
&& table3.discount == 'sample'
&& table4.name == 'hello'
&&(table5.name == 'one' || table5.name == 'two' || table5.name == 'three')
{
if (table1)
{
i = i + 1;
}
}
info(strfmt("Total : %1",i));
}
请帮助,我认为哪里出错了
Pls help, where did i go wrong it think it's with this part
if (table1)
我还尝试精简代码以了解问题出在哪里,
I also tried trimming down the codes to know where the problem arise,
while select forUpdate table1
join table2 where table1.field1 == table2.field1
&& table1.location == 'asia' && table2.modtye == 2
这部分还没有返回结果...当我包含
This part dont return result already... when I include the
&& table1.location == 'asia' && table2.modtye == 2
所以我认为问题就在那里,但是代码有什么问题呢?
So i think, the problem is there, but what is wrong with the code?
我实际上是根据本教程链接建立我的代码的
I based my codes actually from this tutorial link
推荐答案
我建议一个简单的解释,也许是SQL从几个公司或分区返回行?
默认情况下,AX会返回当前分区和公司curext()
的行.
I suggest a simple explanation, maybe the SQL returns rows from a several companies or partitions?
AX by default returns row for the current partition and company curext()
only.
如果使用crosscompany
选项进行选择,它将扫描跨公司:
If you use the crosscompany
option to the select it will scan cross companies:
while select crosscompany table1 ...
您无需测试是否找到了table1,如果找不到,则不会进入循环.
You do not need to test whether table1 is found, if not found it will not enter the loop.
此外,如果您唯一的目的是要计数手动记录的浪费的记录数,那么只需执行一次选择即可:
Also, if your sole purpose is to count the number of records it is wasteful to count manually, a single select will do:
select firstOnly /*crosscompany*/ count(RecId) from table1
exists join table2 where table1.field1 == table2.field1
exists join table3 where table1.field2 == table3.field2
exists join table4 where table3.field3 == table4.field3
exists join table5 where table3.category == table5.recid
&& table1.location == 'asia' && table2.modtye == 2
&& table3.discount == 'sample'
&& table4.name == 'hello'
&&(table5.name == 'one' || table5.name == 'two' || table5.name == 'three');
info(strfmt("Total : %1", table1.RecId));
这篇关于不返回正确计数的x ++脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!