List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:September 14 2002 11:23pm
Subject:Re: Format can I Do this in MYSQL
View as plain text  
At 16:17 -0700 9/14/02, Bryan wrote:
>Using ADO and a jet database I would often format a number so that it
>could have a leading zero(s). For example
>
>Row Employee_number = 123
>Format(employee_number,"0000000") as EMPLOYEE would return 0000123 in
>the EMPLOYEE column. I use it to align data for employeees who don't
>have a 7 digit employee number.
>
>Is there a way of doing something like this in MySQL.

You could try something like this:

LPAD(col_name,7,'0')

Or you could define your column to be a zerofill integer and have
a display width of 7:

mysql> create table t (i int(7) zerofill);
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t set i = 13;
Query OK, 1 row affected (0.01 sec)

mysql> select * from t;
+---------+
| i       |
+---------+
| 0000013 |
+---------+
1 row in set (0.00 sec)

Thread
data normalization questionspeters6 Sep
  • Re: data normalization questionArthur Fuller14 Sep
    • Re-sequencing a query result set with MYSQLDharmendra sawh14 Sep
      • Re: Re-sequencing a query result set with MYSQLPaul DuBois14 Sep
        • RE: Re-sequencing a query result set with MYSQLDharmendra sawh14 Sep
          • RE: Re-sequencing a query result set with MYSQLPaul DuBois15 Sep
            • Format can I Do this in MYSQLBryan15 Sep
              • Re: Format can I Do this in MYSQLPaul DuBois15 Sep
                • RE: Format can I Do this in MYSQLBryan15 Sep
              • Re: Format can I Do this in MYSQLJenny Barton16 Sep
      • Re: Re-sequencing a query result set with MYSQLpeter.brawley15 Sep
  • Re: data normalization questionBobJ14 Sep