将具有Join的SQL查询转换为X ++ Dynamics AX脚本 [英] convert SQL Query with Join to X++ Dynamics AX scripting

查看:65
本文介绍了将具有Join的SQL查询转换为X ++ Dynamics AX脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不那么简单的SQL查询,因为它包含Join

I have a SQL query that is not that simple as it contains Join

SELECT *
 FROM table1 a inner join table2 b on a.field1 = b.field1
 inner join table3 c on a.field2 = c.field2 
 inner join table4 d on c.field3 = d.field3
  inner join table5 e on c.field4 = e.field4
 WHERE a.location = 'asia' AND  b.modType = 1
 and c.discount = 'sample'
 and d.name =  'hello' 
and e.name in ('one', 'two', 'three')

我喜欢将其转换为X ++脚本,这就是我所做的

I like to convert it to X++ scripting, here's what I did

  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 in  ('one', 'two', 'three')

我需要检索要更新的数据

I need to retrieve the data to update

但是x ++是错误的并且不成功.

But the x++ is wrong and unsuccessful.

由于我是X ++编码的新手,希望能对此获得专家意见

Hope to get expert advice on this as I am new to X++ scipting

推荐答案

较旧版本的X ++不支持 in 运算符.改用 || .
此处中所述的受限制格式受支持. ,仅支持枚举.

Older versions of X++ do not support the in operator. Use || instead.
It is supported in a restricted form described here, only supported for enums.

此外,您将需要声明缓冲区:

Also you will need to declare your buffers:

Table1 table1;
Table2 table2;
Table3 table3;
Table4 table4;
Table5 table5;
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')
{
    info(strFmt('%1 %2 %3', table5.name, table4.name, table3.discount));
}

这篇关于将具有Join的SQL查询转换为X ++ Dynamics AX脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆