[ic] Increment integer with preceding zeros

Paul Jordan jordan at gishnetwork.com
Sat Apr 5 23:39:18 CDT 2008


> > On 04/05/2008 08:00 PM, Peter wrote:
> > > On 04/05/2008 07:05 PM, Grant wrote:
> > >> Is there a way to increment an integer like 000001 to end up with
> > >> 000002?  The integer is stored in a MySQL table.
> > >
> > >
> > > Of course, there's a few different ways.  If you give some more
> > details
> > > of what you're trying to do, though, it will be easier to give an
> > > appropriate answer to your question.  Where do you want the
> increment
> > to
> > > occur, and when, etc?
> >
> > I'll give you a bit of code you can use in perl to do it:
> >
> > $i = sprintf('%0' . length($i) . 'd', $i + 1);
> >
> > Peter
> 
> UPDATE table
> set mynumber = mynumber + 1
> WHERE mycode = 123
> 

Heh, not quite right Pal, maybe you mean:

UPDATE table
SET mynumber = LPAD(mynumber + 1, LENGTH(mynumber), '0')
WHERE mycode = 123

/me looks both ways first...

Paul





More information about the interchange-users mailing list