ADD A ZERO TO THE RETURNED VALUE IF THERE IS NO ZERO

Ida B Wells

Total Post:30

Points:210
Posted by  Ida B Wells
 1029  View(s)
Ratings:
Rate this:
Hi Developers!

The following query returns the following sample data from my db.

select mobileno
from Person
sample results:

775623655
0758956556
0756899955
777325656

How can I add a 0 in front if there is no 0 in the returned values?

Thanks in advance. 

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Add a zero to the returned value if there is no zero

    Hi,


    Try as following 

    SELECT CASE LEFT(mobileno,1) 
        WHEN '0' THEN mobileno
        ELSE '0' + mobileno
        end
    FROM Person 

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!