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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Integer to Fixed Width Text 2

Status
Not open for further replies.

Milla

IS-IT--Management
Apr 27, 2000
19
0
0
US
I have a table that has an Integer Value in a Column. We'll call this "sequence number", or "Seq".

I need to reformat the entire column to a 7-character, right-justified, space-padded text field:

In other words:
Code:
Have              Need
=====             =======
1                 0000001
2                 0000002
3                 0000003
4                 0000004
...
245               0000245
246               0000246
...
1034              0001034

Does anyone have a snippet of simple (I'm a rookie) code that can recurse through the table and make this modification?

Thanks!


 
Dim LoopTimes as integer
Dim SequenceNumber as variant
LoopTimes= Len(SequenceNumber)
Do While LoopTimes < 7
SequenceNumber = &quot;0&quot; & SequenceNumber
LoopTimes = LoopTimes + 1
Loop
 
Use the format() function. Example:

?format(7,&quot;0000000&quot;)

Yields 0000007

For an update you could do something like:

update [mytb] set [mytextfield] = format([mynumberfield],&quot;0000000&quot;)


Mike Pastore

Hats off to (Roy) Harper
 
WOW

That was Fast!

I'll try it and let you know.

Thanks very much!
 

Good one MPASTORE, I have never used this method before. I may change some code in some of my databases to this. Worth a star at least!

Tony
 
Worked like a charm and it was SIMPLE.

Thanks, Mike [thumbsup]

(Agree with Tony, definitely worth a star.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top