Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Add a filter in where clause

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
    Martin Dráb 230,198 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
    mimi51340 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
    Martin Dráb 230,198 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
    Gunjan Bhattachayya 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans