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
 Adding Prefix for column

Author  Topic 

jimoomba
Yak Posting Veteran

90 Posts

Posted - 2011-11-21 : 09:21:34
Hi All

Iam having Users table which contains the users information data retrieved from Active directory. The users table contains mobilenumber column also. Now i want to validate for the mobilenumber retrieved if it has the countrycode as '91'. If it does not start with prefix as '91' then i need to append the saved mobile number with the prefix '91'.
For example if the mobile no is '900080000' then it should append as '91900080000'
Kindly let me know the query for this.

Thanks,
Ram

rams

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2011-11-21 : 10:14:45
check for the country code. If the code appears, then append 91 to your mobile number. Does not sound hard at all. what have you tried so far?

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-21 : 11:11:58
[code]
UPDATE Table
SET PhoneNumber = 9100000000+PhoneNumber
WHERE PhoneNumber /100000000 <> 91
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-11-22 : 01:38:05
What is the datatype of mobileno column?

UPDATE Table
SET PhoneNumber = '91'+PhoneNumber
WHERE LEN(PhoneNumber)<=10

or

UPDATE Table
SET PhoneNumber = '91'+PhoneNumber
WHERE PhoneNumber like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'




Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -