Solved

mysql check number length

Posted on 2012-04-09
4
312 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 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 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
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 …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

21 Experts available now in Live!

Get 1:1 Help Now