Quizzes & Puzzles9 mins ago
SQL - Identify numeric values only
3 Answers
Is there a way in SQL I can identify specific values based on characters in the value (i.e. only values with numbers)
Example: From the below table, how do I identify values with no numbers...... (so I's only be hoping to see MANCHESTER, LIVERPOOL and CHESTER)
MANCHESTER
LIVERPOOL
34978987 FRT
CHESTER
CH4JKHB8
Example: From the below table, how do I identify values with no numbers...... (so I's only be hoping to see MANCHESTER, LIVERPOOL and CHESTER)
MANCHESTER
LIVERPOOL
34978987 FRT
CHESTER
CH4JKHB8
Answers
Best Answer
No best answer has yet been selected by Chris100682. Once a best answer has been selected, it will be shown here.
For more on marking an answer as the "Best Answer", please visit our FAQ.Sure there's a better way, but off the top of my head, for SQL Server :
SELECT MyField FROM MyTable WHERE
CHARINDEX('0', MyField)=0 AND
CHARINDEX('1', MyField)=0 AND
CHARINDEX('2', MyField)=0 AND
CHARINDEX('3', MyField)=0 AND
CHARINDEX('4', MyField)=0 AND
CHARINDEX('5', MyField)=0 AND
CHARINDEX('6', MyField)=0 AND
CHARINDEX('7', MyField)=0 AND
CHARINDEX('8', MyField)=0 AND
CHARINDEX('9', MyField)=0
From memory, you have a Postgres database don't you? I suspect there is an equivalent to CHARINDEX.
SELECT MyField FROM MyTable WHERE
CHARINDEX('0', MyField)=0 AND
CHARINDEX('1', MyField)=0 AND
CHARINDEX('2', MyField)=0 AND
CHARINDEX('3', MyField)=0 AND
CHARINDEX('4', MyField)=0 AND
CHARINDEX('5', MyField)=0 AND
CHARINDEX('6', MyField)=0 AND
CHARINDEX('7', MyField)=0 AND
CHARINDEX('8', MyField)=0 AND
CHARINDEX('9', MyField)=0
From memory, you have a Postgres database don't you? I suspect there is an equivalent to CHARINDEX.
For Postgres :
SELECT MyField FROM MyTable WHERE
position('0' in MyField)=0 AND
position('1' in MyField)=0 AND
position('2' in MyField)=0 AND
position('3' in MyField)=0 AND
position('4' in MyField)=0 AND
position('5' in MyField)=0 AND
position('6' in MyField)=0 AND
position('7' in MyField)=0 AND
position('8' in MyField)=0 AND
position('9' in MyField)=0
SELECT MyField FROM MyTable WHERE
position('0' in MyField)=0 AND
position('1' in MyField)=0 AND
position('2' in MyField)=0 AND
position('3' in MyField)=0 AND
position('4' in MyField)=0 AND
position('5' in MyField)=0 AND
position('6' in MyField)=0 AND
position('7' in MyField)=0 AND
position('8' in MyField)=0 AND
position('9' in MyField)=0
or the spazzy way
select myfield from mytable
where myfield not like '%0%'
and myfield not like '%1%'
and myfield not like '%2%'
and myfield not like '%3%'
and myfield not like '%4%'
and myfield not like '%5%'
and myfield not like '%6%'
and myfield not like '%7%'
and myfield not like '%8%'
and myfield not like '%9%'
select myfield from mytable
where myfield not like '%0%'
and myfield not like '%1%'
and myfield not like '%2%'
and myfield not like '%3%'
and myfield not like '%4%'
and myfield not like '%5%'
and myfield not like '%6%'
and myfield not like '%7%'
and myfield not like '%8%'
and myfield not like '%9%'
Related Questions
Sorry, we can't find any related questions. Try using the search bar at the top of the page to search for some keywords, or choose a topic and submit your own question.