473,854 Members | 1,820 Online

# Is there any way to use LIKe operator with interger values

2 New Member
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
6 24571
r035198x
13,262 MVP
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
letmatros
2 New Member
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
r035198x
13,262 MVP
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
deangc
1 New Member
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
rgarrep
1 New Member
WHERE CAST(EMP_id AS VARCHAR(8)) LIKE '24%' really works fine.
Mar 1 '07 #6
r035198x
13,262 MVP
WHERE CAST(EMP_id AS VARCHAR(8)) LIKE '24%' really works fine.
Indeed. It's a good trick for this.
Mar 1 '07 #7