Wildcard search on a numeric field

5 posts, 0 answers
  1. James Harkins
    James Harkins avatar
    11 posts
    Member since:
    Dec 2009

    Posted 04 Mar 2010 Link to this post

    I have a simple question, I hope....

    How do you execute a wildcard search on a  numeric field such as an integer?

    SELECT emp FROM ClaimGridViewExtent as emp WHERE  (ClaimID like %22%)

    ClaimId is an INTEGER
    --
    Error -
    Original Query: SELECT emp FROM ClaimGridViewExtent as emp WHERE  (ClaimID like %22%)
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: Telerik.OpenAccess.Exceptions.QueryException: line 1:65: unexpected char: '%'
    Original Query: SELECT emp FROM ClaimGridViewExtent as emp WHERE  (ClaimID like %22%)

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [QueryException: line 1:65: unexpected char: '%'
    Original Query: SELECT emp FROM ClaimGridViewExtent as emp WHERE  (ClaimID like %22%)]
       Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e) +4
    
  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 10 Mar 2010 Link to this post

    Hi James Harkins,

    The problem here is that the % sign must be surrounded by quotes. However surrounding it with quotes will make it valid only if you are comparing against a string value. Having that in mind this wildcard will only work if you use it to filter string properties.

    Regards,
    Petar
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
  4. James Harkins
    James Harkins avatar
    11 posts
    Member since:
    Dec 2009

    Posted 10 Mar 2010 Link to this post

    Thank you for responding... 

    Is there a method for searching numbers (non string) with a wild card using OQL as this is a feature that SQL query does support.

    Thanks again.
  5. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 10 Mar 2010 Link to this post

    Hi James Harkins,

    Unfortunately it is not possible to use wildcards against numeric fields. What you can do however is take advantage of the built in conversation methods in SQL and convert your integer field to string and then apply a wildcard search on it. This should look something similar to this:
    var result = scope.GetSqlQuery("SELECT * FROM Categories WHERE CONVERT(varchar(20),CategoryID) LIKE '1%'", null ,null).Execute();
    I hope that helps.

    Regards,
    Petar
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. James Harkins
    James Harkins avatar
    11 posts
    Member since:
    Dec 2009

    Posted 10 Mar 2010 Link to this post

    I will give this a try

    Thank you...
Back to Top
DevCraft banner