Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to use LIKE keyword on numeric datatype in a SQL query.

Posted on 2006-07-24
3
Medium Priority
?
244 Views
Last Modified: 2010-04-23
Hi all,
   I have build a generic user control which perform a customized search on data. I am using a datatable namly oDataTable passed to the control. And then I use the select method of oDatatable to search a column data character by character or digit by digit. I have used like keyword in query which is suitable for this situation. It works well when column datatype is char, or varchar. However, when this search performed on a column has numeric datatype then it generates error stating "like cannot be used with Decimal or string datatype".
The code is as follow:

Dim oDataRow as DataRow
oDataRow = oDataTable.Select(ColumnName & " like '" & txtSearch.Text & "%'", ColumnName)

Note: the ColumnName is the Column Name on which I want to perform search and has type numeric.
Note also that if u r going to give me solution as to use ">="  like:
oDataRow = oDataTable.Select(ColumnName & " >= " & txtSearch.Text, ColumnName)

then this will not work because I am going partial searching. This returns all the numbers from a number to be searched. For it returns 9, 10,... for digit 8.
In a nutshell, when I perform search on digit 8, the result should return either 8, if it is not found then 80 or 81, ..., or 89, if these also not found then 800 or 801, ... 899, and so on.

0
Comment
Question by:AfzalHaidry
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
YZlat earned 300 total points
ID: 17169592
try usinf CAST:

WHERE CAST(ColumnName AS nvarchar) LIKE '" & txtSearch.Text & "%'"
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17169601
or

WHERE CAST(ColumnName AS varchar(12)) LIKE '" & txtSearch.Text & "%'"
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question