I am trying to pull information from a table based on the second character of a string.
for example I have information that is listed as.
MM11
MT9
FC4
FT12
I am trying to pull only information that has a T in the second position.
Great! now what if I want to remove the letters and save just the numbers later in the statement.
For example an FT12 and a FT2 would be saved as a 12 and a 2 and then used to say if the 12 is more than the original rating of a 10 then....
As long as you are sure that the remaining characters form a numeric, then:
(Given table TBL with field FLD.)
SQL:
select substring(FLD, 3, len(rtrim(FLD))-2) as NumericField
from TBL
where substring(FLD, 2, 1) = 'T'
If the remaining characters may not be a numeric, then use something like:
SQL:
select case
when isnumeric(substring(FLD, 3, len(rtrim(FLD))-2)) > 0 then substring(FLD, 3, len(rtrim(FLD))-2)
else 0
end as NumericField
from TBL
where substring(FLD, 2, 1) = 'T'
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.