format number in field

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

format number in field

Post by sal21 »

I just have a jet ado conn opned.
my db is access
my table is named Mytable
Into field CODE have a value similar:

0500-1
6875-45
...

How to update, with a sql query to format the right item from "-" in #000000 for all value in column field.
and have a result similar

0500-000001
6875-000045
...

User avatar
Jezza
5StarLounger
Posts: 847
Joined: 24 Jan 2010, 06:35
Location: A Magic Forest in Deepest, Darkest, Kent

Re: format number in field

Post by Jezza »

Hi Sal

Does this string manipulation function help you:

Left(Code,InStr(Code,"-")) & Format(Right(Code,Len(Code)-InStr(Code,"-")),"000000")
Jerry
I’ll be more enthusiastic about encouraging thinking outside the box when there’s evidence of any thinking going on inside it

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: format number in field

Post by sal21 »

Jezza wrote:Hi Sal

Does this string manipulation function help you:

Left(Code,InStr(Code,"-")) & Format(Right(Code,Len(Code)-InStr(Code,"-")),"000000")
hi friend but i need the sql command :cheers: :thankyou:

similar sql="....."

User avatar
silverback
5StarLounger
Posts: 776
Joined: 29 Jan 2010, 13:30

Re: format number in field

Post by silverback »

Sorry - forgot to credit Jezza with the superb code in my earlier posting.
Silverback
=================================================================

I tried this and it worked OK for me.

UPDATE MyTable SET MyTable.Code = Left(

Code: Select all

,InStr([Code],"-")) & Format(Right([Code],Len([Code])-InStr([Code],"-")),"000000");

Hope this helps
Silverback
Last edited by silverback on 05 Oct 2010, 17:17, edited 1 time in total.

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: format number in field

Post by sal21 »

silverback wrote:I tried this and it worked OK for me.

UPDATE MyTable SET MyTable.Code = Left(

Code: Select all

,InStr([Code],"-")) & Format(Right([Code],Len([Code])-InStr([Code],"-")),"000000");

Hope this helps
Silverback[/quote]

Perfect! Tks.
Sal.