November 21, 2011 at 10:25 am
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'. finally I mean I want to check for the country code. If the country code appears, then append 91 to your mobile number.
For example if the mobile no is '900080000' then it should append as '91900080000'
Kindly let me know the query for this.
Thanks,
Ram
November 21, 2011 at 10:31 am
Update MyTable
set MobileNum = '91' + MobileNum
where left(MobileNum, 2) <> '91'
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
November 21, 2011 at 10:50 am
Hi Sean,
Thanks for your spontaneous reply. That worked liked a charm for me, and iam having one doubt in this. Suppose if want to have the telephone country code as a flag and use it for appending the column when the number does not start with telephone country code. could you please help me on this.
Thanks,
Ram
November 21, 2011 at 10:51 am
rams.prsk (11/21/2011)
Hi Sean,Thanks for your spontaneous reply. That worked liked a charm for me, and iam having one doubt in this. Suppose if want to have the telephone country code as a flag and use it for appending the column when the number does not start with telephone country code. could you please help me on this.
Thanks,
Ram
He's already done that for you!
Run the code in transaction to be able to roll it back and see what it does. come back if you have more issues.
You can change <> '91' with different yourcolumn
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply