Solved

mysql check number length

Posted on 2012-04-09
4
298 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
  • 2
4 Comments
 
LVL 82

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 51

Assisted Solution

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

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Loading csv or delimited data files to MySQL database is a very common task frequently questioned about and almost every time LOAD DATA INFILE comes to the rescue. Here we will try to understand some of the very common scenarios for loading data …
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now