DelphiFAQ Home Search:
General :: Databases :: InterBase
Help with InterBase, Borland's open source database.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Having a generator generate a string (00001) instead of an integer (1)

Question:

How to do my generator generate '00001' and not 1? I want my generator to generate a string representation of a number with leading zeroes.

Answer:

InterBase does not have a lot of string functions. You could either write a user-defined function (UDF) - the manual provides an example for a basic string function implemented as an UDF. The downside is that you're going platform specific then.

Or you could use write some (slower) SQL code in your trigger:

I = gen_id(MYGEN, 1);
 S = cast(I as varchar(6));
 
      if (S like '_') then
   S = '00000' || S
 else if (S like '__') then
   S = '0000' || S
 else if (S like '___') then
   S = '000' || S
 else if (S like '____') then
   S = '00' || S
 else if (S like '_____') then
   S = '0' || S;
 
 

Generated 0:00:35 on May 26, 2017