By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,287 Members | 1,284 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,287 IT Pros & Developers. It's quick & easy.

Is there any way to use LIKe operator with interger values

P: 2
Hi,
I have an integer field with 10 digit values.I want to allow the user to search with starting numbers say 5 digits.

if the search is for 123 all the numbers starting with 123 should be displayed. Is there any operator similar to LIKE for this purpose?
Feb 20 '07 #1
Share this Question
Share on Google+
6 Replies


10K+
P: 13,264
Hi,
I have an integer field with 10 digit values.I want to allow the user to search with starting numbers say 5 digits.

if the search is for 123 all the numbers starting with 123 should be displayed. Is there any operator similar to LIKE for this purpose?
I've never heard of it. Maybe your design is wrong then. Do you really must have that column as an integer?
Feb 20 '07 #2

P: 2
Maybe I don't get the problem, but if your values are always 10 digits, then you could do something where you fetch all records with
1230000000<= x <=1239999999
Feb 20 '07 #3

10K+
P: 13,264
Maybe I don't get the problem, but if your values are always 10 digits, then you could do something where you fetch all records with
1230000000<= x <=1239999999
I think they want 123, 1234, 123009 e.t.c to be returned as well.
Feb 20 '07 #4

P: 1
I think they want 123, 1234, 123009 e.t.c to be returned as well.
I think you're probably stuck converting the integer value to a varchar and operating on it as a string.

For example,
WHERE CAST(colname as VARCHAR(10)) LIKE '123%'

Note that depending on your design, this could have performance implications.
Feb 25 '07 #5

P: 1
WHERE CAST(EMP_id AS VARCHAR(8)) LIKE '24%' really works fine.
Mar 1 '07 #6

10K+
P: 13,264
WHERE CAST(EMP_id AS VARCHAR(8)) LIKE '24%' really works fine.
Indeed. It's a good trick for this.
Mar 1 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.