Link to home
Start Free TrialLog in
Avatar of morinia
moriniaFlag for United States of America

asked on

Zero filling zip code in SQL and converting from character to numeric

Experts,

I am coverting a  column from character to numeric in SQL.  I would like to see the "0" at the leading zeroes.  Can someone tell me how to format the output?

This is what I have to convert from character to numeric.


,(select convert( numeric( 5, 0 ), left( member.member_zip, 5 ))) as zip
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

>I am coverting a  column from character to numeric in SQL.  
>I would like to see the "0" at the leading zeroes.
What you are asking is not possible, as no numeric data types support leading zeros.
So ... it can't be done.
To 'pad' a number with leading zeros and display it..

Declare @num int = 1234

SELECT RIGHT('00000' + CAST(@num as varchar(max)), 5)

Open in new window

Avatar of morinia

ASKER

jihorn,

This gives me leading zeroes, but it is  1024 characters.  I want 5 positions numeric.
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of morinia

ASKER

Thanks
Thanks for the grade.  Good luck with your project.  -Jim