Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Add a filter in where clause

(0) ShareShare
ReportReport
Posted on by 50

Hello, 


I would like to create a filter like below but I think substr method is not possible in the where clause. 

How can I manage it ? 

while select * from vendTrans
        join tri_NettingCorrelationAP
           where
              vendTrans.AccountNum == tri_NettingCorrelationAP.TRI_PurchAccount
              && (substr(vendTrans.Voucher,1,3) == "AFG" || substr(vendTrans.Voucher,1,2) == "FF" || substr(vendTrans.Voucher,1,3) == "AF")
              && vendTrans.createdDateTime >= this.dateCompare(SystemDateGet()-365)

Thanks

  • Martin Dráb Profile Picture
    231,837 Most Valuable Professional on at
    RE: Add a filter in where clause

    If you have difficulties to query your data, it usually means that your data model isn't designed correctly. It doesn't support well what you need from it.

    In this case, you seem to be using a part of the voucher ID to categorize transactions, but this categorization should be ideally stored in a separate field. Filtering by such a field would be trivial.

  • mimi51340 Profile Picture
    50 on at
    RE: Add a filter in where clause

    Thanks what do you think by Nevertheless it seems that the root cause is in the data model ?

  • Verified answer
    Martin Dráb Profile Picture
    231,837 Most Valuable Professional on at
    RE: Add a filter in where clause

    Using 'like' sounds like the right approach to me:

    while select vendTrans
    	join tri_NettingCorrelationAP
    		where tri_NettingCorrelationAP.TRI_PurchAccount == vendTrans.AccountNum
    		   && ( vendTrans.Voucher like 'AF*'
    		     || vendTrans.Voucher like 'FF*')

    Nevertheless it seems that the root cause is in the data model.

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Add a filter in where clause

    Hi mimi,

    If you want to use subStr, you can check into using if condition. Otherwise, you can try using like operator

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,025 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,837 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans