morinia
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
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
To 'pad' a number with leading zeros and display it..
Declare @num int = 1234
SELECT RIGHT('00000' + CAST(@num as varchar(max)), 5)
ASKER
jihorn,
This gives me leading zeroes, but it is 1024 characters. I want 5 positions numeric.
This gives me leading zeroes, but it is 1024 characters. I want 5 positions numeric.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
Thanks for the grade. Good luck with your project. -Jim
>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.