PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Logiciels d'hébergement > mailing.database.mysql > Forcing an Intger length
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Forcing an Intger length

Réponse
 
LinkBack Outils de la discussion
Vieux 30/05/2006, 17h33   #1
john.carbonette@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Forcing an Intger length

Hi people,
I've looked around but have not been to find an answer for my question.
I'm looking to force a length of 4 on an integer field. Example if the
field contains an 11, I would like to show it as 0011, or a 9 to show
it as 0009. What do I need to do?

Thanks in Advance.

John

  Réponse avec citation
Vieux 30/05/2006, 18h14   #2
Thomas Bartkus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Forcing an Intger length

<john.carbonette@gmail.com> wrote in message
news:1149003238.785532.70060@y43g2000cwc.googlegro ups.com...
> Hi people,
> I've looked around but have not been to find an answer for my question.
> I'm looking to force a length of 4 on an integer field. Example if the
> field contains an 11, I would like to show it as 0011, or a 9 to show
> it as 0009. What do I need to do?


I am assuming:
a) You have an integer field.
b) That integer field never exceeds 9999 (four digits).
c) You want to query this integer field and have it display padded with
leading zeros as necessary to fill out to four digits.

If a, b, and c, are true - I would use the LPAD (left pad) function thus:
SELECT LPAD({field}, 4, '0') As `FourDigitInt`

You will, of course, modify that to your liking.

The drawback with LPAD() is that if your field value exceeds 9999, it will
truncate (drop digits) to get back down to 4 digits.

Thomas Bartkus


  Réponse avec citation
Vieux 30/05/2006, 18h28   #3
Bill Karwin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Forcing an Intger length

john.carbonette@gmail.com wrote:
> Hi people,
> I've looked around but have not been to find an answer for my question.
> I'm looking to force a length of 4 on an integer field. Example if the
> field contains an 11, I would like to show it as 0011, or a 9 to show
> it as 0009. What do I need to do?


Read about the integer display length syntax (e.g. INT(5)) and ZEROFILL
option here:

http://dev.mysql.com/doc/refman/5.0/...ric-types.html

Regards,
Bill K.
  Réponse avec citation
Vieux 05/06/2006, 18h04   #4
Chander Ganesan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Forcing an Intger length

Bill Karwin wrote:
> john.carbonette@gmail.com wrote:
> > Hi people,
> > I've looked around but have not been to find an answer for my question.
> > I'm looking to force a length of 4 on an integer field. Example if the
> > field contains an 11, I would like to show it as 0011, or a 9 to show
> > it as 0009. What do I need to do?

>
> Read about the integer display length syntax (e.g. INT(5)) and ZEROFILL
> option here:
>
> http://dev.mysql.com/doc/refman/5.0/...ric-types.html


Keep in mind that these are display settings - and typically won't
apply to your applications that interface with the database (such as
PHP/Perl/C). They generally apply to interactive query clients (such
as query browser and the mysql client).

If you need MySQL (or PostgreSQL) training, we offer a wide range of
both. (http://www.otg-nc.com)

--
Chander Ganesan
Open Technology Group, Inc.
One Copley Parkway, Suite 210
Morrisville, NC 27560
Phone: 877-258-8987/919-463-0999

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h09.


Édité par : vBulletin® version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08790 seconds with 12 queries