?
Solved

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

Posted on 2006-07-24
3
Medium Priority
?
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

719 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