This is a migrated thread and some comments may be shown as answers.

Wildcard search on a numeric field

4 Answers 1295 Views
OQL (OQL specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
James Harkins
Top achievements
Rank 1
James Harkins asked on 04 Mar 2010, 08:52 PM
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

4 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 10 Mar 2010, 04:09 PM
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.
0
James Harkins
Top achievements
Rank 1
answered on 10 Mar 2010, 04:32 PM
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.
0
PetarP
Telerik team
answered on 10 Mar 2010, 04:41 PM
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.
0
James Harkins
Top achievements
Rank 1
answered on 10 Mar 2010, 05:14 PM
I will give this a try

Thank you...
Tags
OQL (OQL specific questions)
Asked by
James Harkins
Top achievements
Rank 1
Answers by
PetarP
Telerik team
James Harkins
Top achievements
Rank 1
Share this question
or