Skip to main content

Notifications

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  
  • Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    How to use in clause to search multiple comma seperated values in x++
    ... 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.
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 13,406 Super User 2025 Season 1 on at
    How to use in clause to search multiple comma seperated values in x++
    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
     
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    How to use in clause to search multiple comma seperated values in x++
    Adding to Martin you can also do like,
     
    loop through container and inside the loop select the table buffer using conpeek().
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    How to use in clause to search multiple comma seperated values in x++
    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);
    }

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,969 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans