web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

sql statement in x++

(0) ShareShare
ReportReport
Posted on by 120

Hi, Could anyone please tells me how to write this code in X++?
select salestable.InventSiteId, SALESTABLE.SALESRESPONSIBLE, SALESLINE.CUSTGROUP,
inventtable.INVENTTYPE, inventtable.INVENTSUBTYPE, SUM(salesline.SALESQTY)
from salestable, SALESLINE, INVENTTABLE
where salestable.SALESID == salesline.SALESID &&
inventtable.ITEMGROUPID == salesline.CUSTGROUP &&
INVENTTABLE.ITEMID == salesline.ITEMID &&
SALESTABLE.SALESSTATUS == SalesStatus::Invoiced
group by salestable.INVENTSITEID, salestable.SALESRESPONSIBLE,
salesline.CUSTGROUP, inventtable.INVENTTYPE,
inventtable.INVENTSUBTYPE
order by salestable.INVENTSITEID, salesline.CUSTGROUP, salestable.SALESRESPONSIBLE,
inventtable.INVENTTYPE, INVENTTABLE.INVENTSUBTYPE;

The statement works fine in SQL Query, but not in AX.

Thanks for the help.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Here are some references on how to create a query using x++:

    msdn.microsoft.com/.../aa656402.aspx

    msdn.microsoft.com/.../aa638454.aspx

  • Malcolm Burtt Profile Picture
    1,475 on at

    Hi

    You say that you cannot get the statement to work in AX. In what sense does it not work?

    My guess is that you're having trouble structuring the X++ syntax correctly to handle the group by across mutliple tables where fields (e.g. InventSiteId) appear in multiple tables. If that's your problem you could try adding multiple group by clauses, one for each table. e.g.

          select InventSiteId, SalesUnitId from salesTable

       group by InventSiteId, SalesUnitId

       where salesTable.SALESSTATUS == SalesStatus::Invoiced   

       join ItemType, ItemBuyerGroupId from inventTable  

       group by ItemType, ItemBuyerGroupId

       where inventTable.ItemId == salesLine.ItemId  

       join custGroup, sum(SalesQty) from salesLine

       group by custGroup

       where salesTable.salesId == SalesLine.SalesId

    Note that I'm using different fields than you as this code is coming from AX 2012 and the fields you listed don't exist on the same tables.

    This might still leave you with a problem because I see you have specified the order by field list differently from the group by field list and I don't think AX is going to let you do that.

    Regards

    Malcolm Burtt

    K3 Retail

  • xdudevrb Profile Picture
    195 on at

    I've a similar problem, converting a sql server query to ax2012 x++,  this is new attemp but still no success, can you help me with the correct syntax.

    while select ItemId,LastUpdDatePhysical,AvailPhysical,InventDimId from inventSum

            group by ItemId, LastUpdDatePhysical, AvailPhysical, InventDimId

                     join wMSLocationId, inventDimId from inventDim

                          group by wMSLocationId, inventDimId

                                   where inventSum.InventDimId == InventDim.inventDimId

                     join gstAgingDate,ItemId from inventJournaltrans

                          group by gstAgingDate, ItemId

                                   where inventJournaltrans.ItemId == inventSum.ItemId

                     join BOMUnitId,ItemId,dataAreaId from inventTable

                          group by BOMUnitId, ItemId, dataAreaId

                                   where inventTable.ItemId == inventSum.ItemId

                                         && inventTable.dataAreaId == inventSum.dataAreaId

                     join ItemId,dataAreaId from inventItemgroupitem

                          group by ItemId, dataAreaId

                                   where inventItemgroupitem.ItemId == inventTable.ItemId

                                         && inventTable.dataAreaId  == inventItemgroupitem.ItemDataAreaId

                     join ItemGroupId,gstItemGroupType,dataAreaId from inventItemgroup

                          group by ItemGroupId, gstItemGroupType, dataAreaId

                                   where inventItemgroupitem.ItemGroupId == inventItemgroup.ItemGroupId

                                         && inventItemgroupitem.ItemGroupDataAreaId == inventItemgroup.dataAreaId

                                         && inventSum.AvailPhysical > 0

                                         && inventItemgroup.gstItemGroupType == 'RAW'

  • KyleLeBarre Profile Picture
    747 on at

    How did you even find this 3 year old post?

  • xdudevrb Profile Picture
    195 on at

    Desperation and patience!  :-D

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 28

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans