Solved

mysql check number length

Posted on 2012-04-09
4
357 Views
Last Modified: 2012-05-01
hi,
is it possible to check a numbers length in mysql because the zeros are missing off the beginning of some numbers.. is there away to check if its 9 in length and add a zero in the beginning if it is.

thanks in advance
0
Comment
Question by:MK15
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37825766
'Numbers' do not have leading zeros (or trailing zeros to the right of a decimal point) because they contribute nothing to the value.  If you want leading zeros, you must convert it to a string and check it there.
0
 
LVL 56

Assisted Solution

by:HainKurt
HainKurt earned 500 total points
ID: 37825980
try:

right('00000000'+num,9)
0
 
LVL 56

Accepted Solution

by:
HainKurt earned 500 total points
ID: 37825985
or use

lpad(num, 9, '0')

you may need to cast it

lpad(cast(num as char), 9, '0')
0
 

Author Closing Comment

by:MK15
ID: 37914223
thanks guys
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question