We help IT Professionals succeed at work.

how to extract last 6 digits from a varchar, sql

tanj1035
tanj1035 asked
on
101 Views
Last Modified: 2017-04-17
hi experts, I want to extract last 6 digits  from 227-78-7834 (this is a varchar), the result will be 787834.

Thank you.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2010

Commented:
SELECT MyColumn, RIGHT(REPLACE(MyColumn, '-', ''), 6) AS LastSix
FROM MyTable
Analyst Assistant
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
thanks.

Author

Commented:
Thank you for your reply, Patrick. but it did not return the result correctly.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.