Tuesday, March 27, 2012

Filling empty characters

Hi,

I am importing barcodes however they are all different lengths and I need to bring them all up to 14 characters by adding zero's to the beginning of them (up to when the field is full).

The only way I can think is doing a count on the char length and then adding zero's in a loop but I think there must be an easier way? Any help appreciated.

Thanks
TimWhat about this?

declare @.line varchar(50),@.len int
set @.line='12345'
set @.len=10
select isnull(replicate('0',@.len-len(@.line)),'')+@.line|||..or the more low-tech:

set @.line = right(14, '00000000000000' + @.line)

blindman|||how low can you go?

Hey, I have to lookup just to see the top of the gutter...

No comments:

Post a Comment