Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

mysql check number length

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
MK15
Asked:
MK15
  • 2
2 Solutions
 
Dave BaldwinFixer of ProblemsCommented:
'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
 
HainKurtSr. System AnalystCommented:
try:

right('00000000'+num,9)
0
 
HainKurtSr. System AnalystCommented:
or use

lpad(num, 9, '0')

you may need to cast it

lpad(cast(num as char), 9, '0')
0
 
MK15Author Commented:
thanks guys
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now