Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to use prefix

Author  Topic 

ramyasre
Starting Member

16 Posts

Posted - 2011-05-13 : 08:05:33
Hi,

I had a table like as follows

name mobileno
_______________
ree 9954452344
yeew 8943234894
hkjk 9748445848
adsd 7889978784

Now i want to add '0' for all mobile no's the output is like as

name mobileno
_______________
ree 09954452344
yeew 08943234894
hkjk 09748445848
adsd 07889978784

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-05-13 : 08:14:40
if datatype of mobileno is character (like varchar):
select
name,
'0' + mobileno
from table



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-05-13 : 08:15:25
What is about mobileno's that have already a leading zero?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

tmaiden
Yak Posting Veteran

86 Posts

Posted - 2011-05-13 : 10:26:35
SELECT name, '0' + CAST(mobileno AS VARHCAR(10)) AS mobileno
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-05-13 : 11:25:46
RTRIM((REPLICATE('0',11) + CONVERT(varchar(11),mobileno)),11)

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

akonmask

5 Posts

Posted - 2011-05-13 : 17:19:28
The sql prefix is used to create a valid XML ID, IDREF, or IDREFS attribute. Also The values of ID type must be distinct in an XML document.


Go to Top of Page
   

- Advertisement -