sql - How to extract US zip codes and check range -
i have table of addresses postal codes , canada. in our system assign territories based on zip code ranges need extract addresses , check whether within given range. tables this: key postalcode --------------------------- 1 58230 2 49034-9731 3 98801 4 m5h 4e7 i run select statement select key, convert(int, left(ltrim(rtrim(postalcode)),5)) pcode table left(postalcode, 5) not '%[^0-9]%' and results return table expected. key postalcode -------------------------- 1 58230 2 49034 3 98801 i wrap alias , attempt check range. select key, pcode (select key, convert(int, left(ltrim(rtrim(postalcode)),5)) pcode table left(postalcode,5) not '%[^0-9]%') x x.pcode between 58000 , 59000 sql server 2008 returns error msg 245, level 16, state 1, line 1 convers...