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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to use in clause to search multiple comma seperated values in x++

(1) ShareShare
ReportReport
Posted on by 97
Hi everyone i have a requirement where i want to search container values in select query
below is a demo example 
 
container test = [‘A’ , ‘B’];
DemoTable Demotable;// it has one field teststring of string type
 
String testStr = con2str(test);// comma seperated values of container
 
select demotable where demotable.teststring in test
 
the above query gives an error and reason behind that IN clause is only supported with enums like if i have container with enum values then the above query would have worked
 Query : is there any other way to search comma seperated values in select statement in d365 or search container values in sql query in x++
 
thanks for the help and replies  
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at
    Use Query* classes instead of the select statement. Iterate the container and add a range for each value. For example:
    Query query = new Query();
    QueryBuildDataSource qbds = query.addDataSource(tableNum(DemoTable));
    
    for (int i = 1; i <= conLen(test); i++)
    {
        qbds.addRange(fieldNum(DemoTable, TestString)).value(queryValue(conPeek(test, i)));
    }
    
    QueryRun qr = new QueryRun(query);
    while (qr.next())
    {
        DemoTable demoTable = qr.getNo(1);
    }
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    Adding to Martin you can also do like,
     
    loop through container and inside the loop select the table buffer using conpeek().
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,398 Super User 2025 Season 2 on at
    Hi,
    i think you can use the List into the range value.
    e.g.
    Query                   query;
    QueryBuildDataSource    qbds;
    List                    listRange;
    queryBuildRange         qbr;
    
    listRange   = new List(Types::String);
    query       = new Query();
    qbds        = query.addDataSource(tableNum(<YourTable>));
    
    listRange.addEnd("1st value");
    listRange.addEnd("2nd value");
    .
    .
    listRange.addEnd("n value");
    qbr         = qbds.addRange(fieldNum(<YourTable>, <FieldRange>));
    qbr.value(SysQueryRangeUtil::queryListRange(rangeList));
    Best regards,
    Mohamed Amine Mahmoudi
     
  • Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at
    ... but you would still need to iterate the container as shown in my code. You'd just first add values to a list instead of directly adding a range.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 464 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans