Link to home
Create AccountLog in
Avatar of tanj1035
tanj1035

asked on

how to extract last 6 digits from a varchar, sql

hi experts, I want to extract last 6 digits  from 227-78-7834 (this is a varchar), the result will be 787834.

Thank you.
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

SELECT MyColumn, RIGHT(REPLACE(MyColumn, '-', ''), 6) AS LastSix
FROM MyTable
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of tanj1035
tanj1035

ASKER

thanks.
Thank you for your reply, Patrick. but it did not return the result correctly.