C
C
CityzenUNDEAD2020-04-12 18:28:21
Transact SQL
CityzenUNDEAD, 2020-04-12 18:28:21

How to convert string '5$' to number?

Zdarov)
I have several fields in the table where records of this kind are '5$', '15$', '24$'.
I need to sort the data by records where it is a string no more than '18$'.
How to convert such a record to a number so that sorting can be done?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
d-stream, 2020-04-12
@CityzenUNDEAD

for example, use cast, after clearing non-numeric characters, for example, using replace

K
Konstantin Tsvetkov, 2020-04-12
@tsklab

DECLARE @Test TABLE ( S VARCHAR(5))
INSERT @Test VALUES ('5$'), ('15$'), ('24$')

SELECT S FROM @Test WHERE RIGHT( '00' + S, 3 ) < '18$'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question