Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Fetchxml compare string with greater than operator

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I want to search for companies between a range of zip codes.

Example:

zip code < 50000

and

zip code > 40000

But it seems, that I can't do that with the advanced find, correct ? Is it possible to do this with fetchxml ?

BTW, the zip code can also be something like: AV300

In this case it should also do the same string comparison.

*This post is locked for comments

  • Aiden Kaskela Profile Picture
    Aiden Kaskela 19,692 on at
    RE: Fetchxml compare string with greater than operator

    Divyang,

    Through Fetch XML you can use gt and lt operators on string fields but they do sting comparisons, not numeric. Suppose you had a string field with values:

    100

    100000

    20000

    5000

    9

    If you queried for value gt 40000, you would get back 5000 and 9.

  • Suggested answer
    Divyang Shukla Profile Picture
    Divyang Shukla 355 on at
    RE: Fetchxml compare string with greater than operator

    No it is not possible, As zip code is String we cannot filter using gt or lt. But we can use below listed operators to filter.

    • Equals
    • Does not equal
    • Contains
    • Does not contains
    • Beings with
    • Does not Being with
    • Ends with
    • Does not End with
    • Contains Data
    • Does not Contains Data
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Fetchxml compare string with greater than operator

    Hi Aiden,

    thats exactly what I need. Thanks a lot !

    I dont have my laptop with me so I couldnt test it right a way.

  • Verified answer
    Aiden Kaskela Profile Picture
    Aiden Kaskela 19,692 on at
    RE: Fetchxml compare string with greater than operator

    Hi Donny,

    Yes, you can do that through fetch xml, I just ran this test looking for an account with postal code 12345.

    <fetch count="25">
    	<entity name="account">
    		<attribute name="address2_postalcode" />
            <filter type="and">
                <condition attribute="address2_postalcode" value="12344" operator="gt"/>
            </filter>
    	</entity>
    </fetch>


    Changing the value in the condition changes the results as you'd expect.

    A word of warning though - the condition here is doing a string compare and not a numeric compare. You could do the same comparison with Name:

    <condition attribute="name" value="B" operator="gt"/>

    would bring back accounts whose name is "B ", "B1", anything that doesn't start with A.

    Hope this helps! I'd appreciate if you'd mark this as Answering your question.

    Thanks,

      Aiden

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans