преобразование SQL-запросов с помощью Join в сценарии X ++ Dynamics AX - PullRequest
0 голосов
/ 24 мая 2019

У меня есть SQL-запрос, который не так прост, поскольку он содержит 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 ++, вот что я сделал

  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')

Мне нужночтобы получить данные для обновления

Но x ++ неправильный и неудачный.

Надеюсь получить совет специалиста по этому вопросу, поскольку я новичок в X ++ scipting

1 Ответ

1 голос
/ 24 мая 2019

Более старые версии X ++ не поддерживают оператор in . Вместо этого используйте || .
Он поддерживается в ограниченной форме, описанной здесь , поддерживается только для перечислений.

Также вам нужно будет объявить ваши буферы:

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));
}
...