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)

How to use AX built in functions in select query

(0) ShareShare
ReportReport
Posted on by

Hi All,

Consider a table customer as below

AccNo            Name

--------------------------------

1-101-1111   Sam

2-101-1112   Tom

3-201-1113   Tim

4-202-1114   Jim

5-203-1012   Jack

--------------------------------

I want a select query to get Names of customer having "101" from 3rd to 5th position.

I can achieve the above requirement as below

customer cus;

;

while select cus      

{

    if(subStr(cus.AccNo,3,3) == "101")

    {

         // do something

    }

}

But i need something as below so that i can reduce the iteration of records.

customer cus;

;

while select cus

     where subStr(cus.AccNo,3,3) == "101"

{

    // do something

}

Thanks in advance,

Sai

*This post is locked for comments

  • Suggested answer
    sshaheen Profile Picture
    127 on at

    You could use the 'like' keyword and wildcards to put a range on your query. It may not be the perfect solution, but it will limit your selection to only those records with have the value '-101-' in them somewhere.

    while select cus    

     where cus.AccNo like "*-101-*"

    {

      if(subStr(cus.AccNo,3,3) == "101")

      {

           // do something

      }

    }

  • Suggested answer
    Dick Wenning Profile Picture
    8,705 Moderator on at
  • Suggested answer
    Community Member Profile Picture
    on at

    while select cus

        where cus.AccNo  LIKE '?-101-*'

    ? represents any ONE character, * zero or more characters.

  • Community Member Profile Picture
    on at

    Hi All,

    Thanks for ur answers...!!!

    I want to use a function on a table column in where condition. Suppose I have some date of birth column in the same table if a need to use a function year on dob column.

    Is it possible to apply some built in ax functions on table column in select statement?

  • Martin Dráb Profile Picture
    241,637 Most Valuable Professional on at

    You can't expect SQL Server to call some X++ methods. If you wrote direct SQL code, you would be able to to call builtin functions of SQL Server, but that's also not possible from AX, with two exceptions:

    • Using a computed column in a view
    • Calling a "direct" SQL query (e.g. through Statement class in AX or a framework in .NET, such as Entity Framework)
  • Verified answer
    Community Member Profile Picture
    on at

    No, in X++ SQL query it is not possible.

    You can have this kind of behaviour using native SQL statement execution

    Create a connection object

    Create SQL string

    execute SQL command, which will give you the ResultSet

    Loop through the ResultSet and implement the logic

    Here in this SQL string, again you will not be able to use X++ functions you need to use SQL functions to implement the logic.

    Please verify and let me know if you need further technical support in implementing above solution

  • Dick Wenning Profile Picture
    8,705 Moderator on at

    Sai.peddinti

    could you please verify the used answer, there are a lot of good solution above, they all are different.

    just verify the one, you have used.

  • Community Member Profile Picture
    on at

    Thanks all for your time...

  • Community Member Profile Picture
    on at

    Hi

    I am trying to insert into temp table  for generating report through data provider using class but getting syntax error

    //

    insert_recordset WorkflowTrackingStatusTableTemp (WORKFLOWTRACKINGSTATUSTABLERECID,Purchreqid1)

    select RECID, subStr(document,22,13) from WORKFLOWTRACKINGSTATUSTABLE

  • Martin Dráb Profile Picture
    241,637 Most Valuable Professional on at

    Avinash, have you read the discussion above? If so, you should already know that you can't use substr() there and why and which workaround you have available.

    By the way, are you sure that copying all data from WorkflowTrackingStatusTable (without any filter) every time is a good idea? And if you sufficiently filter the data, maybe you'll be able to copy the data between buffers in X++, when you can use X++ functions suchas subStr().

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Prashant Singh Profile Picture

Prashant Singh 2

#1
nmaenpaa Profile Picture

nmaenpaa 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans