How to select numeric value from nvarchar column in sql server?
I have table like
Create table Producttbl ( sno nvarchar(100),sname nvarchar(200),price nvarchar(100))
Values are
sno sname price
1 aaa 1.50
2 ccc 5.30
abc xxx abc
3 dsd kkk
nn dss 5.1
Price column is nvarchar
it accept all kind of data like string or numeric.
From that table, I want to select results like this:
sno sname price
1 aaa 1开发者_StackOverflow中文版.50
2 ccc 5.30
Please help me.
You presumably want sno
values which consist of digits and only digits (otherwise, you need to specify which "numeric" types you wish to accept):
select * from ProductTbl where sno not like '%[^0-9]%'
We use a double negative check, to exclude sno
values which contain a non-digit character.
Have you tried using the isnumeric function?
SELECT sno,sname
FROM ProductTbl
WHERE ISNUMERIC(sno)=1
You should read up on the isnumeric documentation to be sure that it returns the results you expect. (see comments below).
精彩评论