Solved

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

Posted on 2006-07-24
3
230 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 100 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

832 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