Forum Discussion

Former_Member's avatar
Former_Member
Accelerator III
8 years ago

How to convert SQL to AML

How to convert SQL to AML use IOM.dll version 11.0.0.6812 below: SELECT MP.* , MN.keyed_name AS MN_keyed_name FROM Manufacturer_Part MP LEFT JOIN Manufacturer MN ON(MP.manufacturer = MN.ID) WHERE ( MP.ITEM_NUMBER = 'CPART5566a' AND MP.manufacturer IS NULL ) OR ( MP.ITEM_NUMBER = 'CPART5566a' AND MN.keyed_name = 'MAKRT5566b' ) ORDER BY modified_on  

5 Replies

  • <AML> <Item type='Manufacturer Part' action='get'> <item_number>CPART5566a</item_number> <or> <manufacturer> <Item type='Manufacturer'>MAKRT5566b</Item> </manufacturer> <manufacturer condition='is null' /> </or> </Item> </AML>
  • I already edit as below and result is OK. Thanks you very much! <AML> <Item type='Manufacturer Part' action='get'> <item_number>CPART5566a</item_number> <or> <manufacturer> <Item type='Manufacturer'> <keyed_name>MAKRT5566b</keyed_name> </Item> </manufacturer> <manufacturer condition='is null' /> </or> </Item> </AML>  
  • Please for help with SQL below: SELECT MP.* , (CASE WHEN MN.keyed_name IS NULL Then '1' ELSE MN.keyed_name END) AS MN_keyed_name FROM Manufacturer_Part MP LEFT JOIN Manufacturer MN ON(MP.manufacturer = MN.ID) WHERE ( MP.ITEM_NUMBER = 'CPART5566a' AND MP.manufacturer IS NULL ) OR ( MP.ITEM_NUMBER = 'CPART5566a' AND MN.keyed_name = 'MAKRT5566b' ) ORDER BY modified_on
  • AML is not working as SQL. You can apply AML to get data from the DB (and get the DB value of the keyed_name) and then you have 2 options:
    1. You can pull all Items of type Manufacturer that keyed_name is_null and update the keyed_name value of each Item of type Manufacturer to "1":
      Item queryResult = this.getInnovator().applyAML({@yourAML});
      Item manufacturersWithEmptyKeyedName = queryResult.getItemsByXPath("//Item[@type='Manufacturer' and keyed_name/@is_null='1']");
      
      for (int i = 0; i < manufacturersWithEmptyKeyedName.getItemCount(); i++) {
       	string keyed_name = manufacturersWithEmptyKeyedName.getItemByIndex(i).getProperty("keyed_name", "1");
      }
    2. In your code when ever you want to get keyed_name property use getProperty function with 2 parameters, when first one is property name and second one is "default" value of 1. So the idea with this method that if property in DB was null it will return the second parameter (in your case "1")
      string keyed_name = someItem.getProperty("keyed_name", "1")
  • Beacause large amount for data result, so performance of method above will slower than SQL query ? Further: with case as below, process will difficult and slow than more if not used query SQL SELECT * FROM ABC XXX INNER JOIN (SELECT MP.* , (CASE WHEN MN.keyed_name IS NULL Then ‘1’ ELSE MN.keyed_name END) AS MN_keyed_name FROM Manufacturer_Part MP LEFT JOIN Manufacturer MN ON(MP.manufacturer = MN.ID) WHERE ( MP.ITEM_NUMBER = ‘CPART5566a’ AND MP.manufacturer IS NULL ) OR ( MP.ITEM_NUMBER = ‘CPART5566a’ AND MN.keyed_name = ‘MAKRT5566b’ ) ORDER BY modified_on) YYY ON(XXX.ITEM_NUMBER = YYY.ITEM_NUMBER AND XXX.keyed_name = YYY.keyed_name)