I have a very simple code that I am trying to run but for reasons that I do not understand, it is not working. Here's my code:
WITH CTE AS
(
    SELECT DISTINCT OrderNo
    FROM OrderDet
    WHERE PartNo LIKE '%.%'
      AND OrderNo NOT LIKE '%[a-z]%'
)
SELECT * 
FROM CTE
WHERE CAST(CTE.OrderNo AS INT) >= 21187
Running this code throws the following error:
Conversion failed when converting the varchar value '20361E' to data type int.
Now I am aware that there are OrderNo values that contain an 'E', however, as far as I'm concerned, I'm filtering them out in the CTE.  If I run the statement in the CTE by itself, I get 580 records, none of which have any letters at all.  
What's going on here?
 
     
    