How to add plus(+) sign in every row of a column using SQL query?

Vishal

I have a database with a column containing phone numbers. I want to add plus(+) sign in the beginning of every phone number.

UPDATE Table 
SET Phone = CONCAT('+', Phone)

This is the query I'm using to insert any other character, but it doesn't seem to work with + sign. It says 0 row(s) affected Rows matched: 4023 Changed: 0 Warnings: 0, which means nothing has changed.

Even if I do SET Phone = CONCAT('+91', Phone), only 91 is being inserted and not the plus sign.

Sergey Martynov

I think I understood what's going on here. Your Table is probably using integer data type for Phone column. In this case Phone = CONCAT('+91', Phone) implicitly converts value to character type, adds leading "+" but then converts it back to integer type to store value.

You might want to do something like

ALTER TABLE `Table` MODIFY Phone Varchar(100);

(please choose column type accordingly)

I reproduced it here http://sqlfiddle.com/#!9/5b3a651/1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

For every row how to add a class name on the <th> based on the value on a particular column using Datatables

SQL Server - Add row for every distict column value

How to divide a value of a column to the total value of that column for every row in SQL?

How do I remove the first two characters of every row in this column using SQL?

How can I replace the first two characters of every row in a specific column using SQL?

How to select a row for every location for every day using SQL?

How to add division sign / times sign / plus sign in xcode 7?

How to pivot a column into a row for sql query

How to add strings and special characters to every row in dataframe in new column?

How to add a string to every even row in a pandas dataframe column series?

Show different row and column data in one column using SQL query

How can I run a SQL query iteratively for every row in a table?

How to run a specific sql query for every row in the table?

How to execute a query on an unrelated table for every row in SQL

SQL : How to query selecting only first row in every hour?

How to convert every other row to column in T-SQL?

How to add column in table grouped by value and max value in date column using sql query?

How to optimize my query speed (avoid using subselect for every row)?

how to add a plus sign and milliseconds to a date in postgresql?

How to add a plus minus sign to a label

How to add a plus sign to a JS Counter?

How to add a sign (;) to every 5 word?

How to subtract two row's date within same column using a SQL query showing days?

How do i show the name of a column as a row data using a sql query?

How can I subtract two row's values within same column using sql query?

how to get sql select query result as column vs value wise instead of row wise without using PIVOT

How can I subtract two row's values within same column using a SQL query?

Using SQL, how do I select which column to add a value to, based on the contents of the row?

Add quatation marks to every row of specific column