1

I have a table called 'testTable' with two columns, 'id' that is auto incremented and 'someValue'.

The data contained in the 'someValue' column are: 12, 1.2, .4, 1d4, +, -, .

I want to select only the numeric values. But when I use the following query:

SELECT someValue, ISNUMERIC(someValue) 
FROM testTable;

all the values are true. And for the query:

SELECT * FROM testTable 
WHERE ISNUMERIC(someValue) = 1;

all the values are being returned.

I just want 12, 1.2 and .4 .

How can I achieve this?

UPDATE:

The data type for the column someValue is varchar(50).

11

1 Answer 1

5

SETUP:

CREATE TABLE SomeTable
(
  ID INT,
  Value NVARCHAR(250)
)


INSERT INTO SomeTable (ID, Value) VALUES (1, '12')
INSERT INTO SomeTable (ID, Value) VALUES (2, '1.2')
INSERT INTO SomeTable (ID, Value) VALUES (3, '.4')
INSERT INTO SomeTable (ID, Value) VALUES (4, '1d4')
INSERT INTO SomeTable (ID, Value) VALUES (5, '+')
INSERT INTO SomeTable (ID, Value) VALUES (6, '-')
INSERT INTO SomeTable (ID, Value) VALUES (7, '.')

QUERY:

SELECT * FROM SomeTable WHERE ISNUMERIC(Value+'d0')=1

RESULT:

ID  VALUE
1   12
2   1.2
3   .4
Sign up to request clarification or add additional context in comments.

1 Comment

It worked. Thanks. But could you explain how it worked. What does ISNUMERIC(Value+'d0') do? What significance does 'd0' have?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.