You could use the TRANSLATE
function to determine if LEFT( LTRIM( hos.hpid ), 3 )
contains letters.
Calling the TRANSLATE
function in the following manner replaces all uppercase capital letters from the input string with the letter A:
TRANSLATE( inputString,
'AAAAAAAAAAAAAAAAAAAAAAAAA',
'BCDEFGHIJKLMNOPQRSTUVWXYZ'
)
Here's how to restrict the TRANSLATE
function to evaluate just the first three characters of the column:
select pat.f1, hos.hpid, hos.hpcd
from patall3 pat
join hospidl1 hos on pat.f1=hos.hpacct
where TRANSLATE(
LEFT( LTRIM( hos.hpid ), 3 ),
'AAAAAAAAAAAAAAAAAAAAAAAAA',
'BCDEFGHIJKLMNOPQRSTUVWXYZ'
) <> 'AAA'
order by pat.f1;
;
That query will only block values that contain letters for all of the first three characters ('AAA', 'AAB', 'AAC', etc.). If you'd rather block rows that contain a letter in any of the first three characters, then use this query instead:
select pat.f1, hos.hpid, hos.hpcd
from patall3 pat
join hospidl1 hos on pat.f1=hos.hpacct
where TRANSLATE(
LEFT( LTRIM( hos.hpid ), 3 ),
'AAAAAAAAAAAAAAAAAAAAAAAAA',
'BCDEFGHIJKLMNOPQRSTUVWXYZ'
) NOT LIKE '%A%'
order by pat.f1;
;