Home > DeveloperSection > Forums > Add a zero to the returned value if there is no zero
Ida B Wells
Ida B Wells

Total Post:30

Points:210
Posted on    July-08-2013 8:49 AM

 MSSQL Server MSSQL Server 
Ratings:


 1 Reply(s)
 732  View(s)
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. 



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    July-08-2013 9:01 AM

Hi,

Try as following 

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

Don't want to miss updates? Please click the below button!

Follow MindStick