Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Padding out a field of numerics

Status
Not open for further replies.

grayt26

Technical User
Jun 2, 2006
26
GB
Hi,

I have a field of numeric values of different lengths, example

20
200
20000

I need these all to be padded out so that
00020
00200
02000

I thought that there was a command that could do this but i can not find it.

Thanks
 
Apologies,

SQLSister also had a good comment depending on your datatypes for the field in question.
 
can you tell me why

Right('0000000000'+field,10)


does not work, it is not adding the zero's, it is just ignoring them.

I have also tried

cast(Right('0000000000'+hosp,10) as varchar(36))

still no zero's
 
Are you selecting or trying to update the table? If it is an update, what is the datatype (see noted on other post about them being ignored if it is a numeric).
 
I was doing a select, testing before i do an update. I have changed the field to varchar now and it works ok with the zero's but i don't understand why it never liked the cast i used.
 
I have also tried

cast(Right('0000000000'+hosp,10) as varchar(36))

still no zero's

In this case you would need to cast BEFORE you try to add the 0000 to hosp

Code:
Right('0000000000' + convert(varchar(10), hosp), 10)

*tested


[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top