If you store varchar or numeric values in the same field then need to filter numeric values some times use this technique in that time to filter record.
Try below example to get numeric values record only
Create table like below
create table emp (eno varchar(50), empname varchar(50),sal bigint)
Insert some values in that table with varchar and numeric employee no.
insert into emp values('101','Ravindran','25000')
insert into emp values('102','James','18000')
insert into emp values('106','Mike','12000')
insert into emp values('M012','Manger','45000')
insert into emp values('MM2','Assitant Manager','12000')
insert into emp values('MMM','Clerk','8000')
Now we are going to filter only numeric employee number record using below query
select * from emp where ISNUMERIC(eno) = 1
If you want only filter record more than 105 eno then use like below query to find out . In this query I eliminate NULL, Varchar records and cast that eno to int then filter
--CAST varchar to nvarchar
select * from emp where ISNUMERIC(eno) = 1 and CAST(isnull(eno,0) as nvarchar) > 105
ConclusionI hope this article is help you to know about filtered database field record based on numeric fields and apply conditions for those numeric fields and apply further filter too.
No responses found. Be the first to comment...