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

Announcements

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
    238,642 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,767 Super User 2026 Season 1 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
    238,642 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 673 Super User 2026 Season 1

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 280 Super User 2026 Season 1

#3
Martin Dráb Profile Picture

Martin Dráb 213 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans