Conditional Number Of Leading Zeros Follow
I need to create a template that will work with a variable no of batch sizes (e.g. could be 1,000, 10,000, 100,000 records in a batch). Our manufacturing guys want the number of digits to be the same and the card no (and 3 other numeric fields for cartons and skids) to be padded with zeros to the length of longest field
if there are 1,000 records I need to use 0001, 0002, ...0010.. 0999, 1000
if there are 10,000 records I need to use 00001, 00002, ...00010.. 00999, 09999, 10000
So basically leading zeros needs to Len(Max(CardNo)) - Len(CardNo)
Card No =1, Max CardNo = 1000. no of zeros is 4-1=3 - Result = 0001
Card No =123, Max CardNo = 1000. no of zeros is 4-3=1 - Result = 0123
Card No =1000, Max CardNo = 1000. no of zeros is 4-4=0 - Result = 1000
Could someone point me right direction?
Please sign in to leave a comment.