Pad zero to right sidein sql

I have column in my table pin_code whose size must be 6 chars ,but there are some values present in tbale with less that 6 chars.It have 2,3,4 or 5 chars values,i WANT TO MIGRATE THOSE VALUES ,Want to add zero to right side according to therir current content
Fo example
if one row in column have pin _code as "1" now want to migrat it as "100000" want pass 5 zero to right side
I want migrate the data for all rows who may have 2char pin code,3,4 or 5

Plz suggest me some function ,or common way to migarte all values in table
select * from t_clnt_address
case when len(pin_code)=1 then pin_code+'00000'
 when len(pin_code)=2 then pin_code+'0000'
 when len(pin_code)=3 then pin_code+'000'
 when len(pin_code)=4 then pin_code+'00'
when len(pin_code)=5 then pin_code+'0'
end 
 
but its not working

Open in new window

LVL 1
winsoftechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brejkCommented:
SELECT RIGHT('000000' + MyVal, 6)
0
brejkCommented:
In your case:

1. If pin_code should be in the result set

select RIGHT('000000' + pin_code,6) from t_clnt_address

2. If pin_code should be used for sorting

select * from t_clnt_address order by RIGHT('000000' + pin_code,6)
0
appariCommented:

select *, left( pin_code + '000000', 6)
 from t_clnt_address
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

brejkCommented:
Ugh, sorry for my padding right instead of padding left ;-)
0
winsoftechAuthor Commented:
Actually i want to update the all pin code whose length is less than 6 .
for that i want update statment with padding zero to right
0
brejkCommented:
Assuming there are no trailing blanks in pin_code column and that performance is not the case here:

UPDATE t_clnt_address
SET pin_code = LEFT(pin_code + '000000',6)
WHERE LEN(pin_code) < 6
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
winsoftechAuthor Commented:
Thanks !!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.