Question

I have a table of items (let's call it WIDGET) that each have their own eight-digit barcode numbers stored in a VARCHAR field (let's call it BARCODE; the table's primary key is in a separate integer column ID). My problem is that some rows include the leading zeros, while others do not. I would like to update all the existing records (several hundred in all) to eight digits for the sake of consistency.

  • 100000001
  • 23400000234
  • 567800005678
  • 0000901200009012

I know FrontBase is SQL-92 compliant, but SQL-92 has no function specifically for left-padding strings. I already came up with a solution, but I am posting this question to see if anyone can think of a better way of doing this than I did.

No correct solution

OTHER TIPS

This seems to work (at least in FrontBase 5.2.9):

UPDATE WIDGET SET BARCODE =
SUBSTRING('00000000' || BARCODE FROM CHAR_LENGTH(BARCODE) + 1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top