Question:
SQL update statement to change integer to have a 1 in front of it?
anonymous
1970-01-01 00:00:00 UTC
SQL update statement to change integer to have a 1 in front of it?
Six answers:
balanse
2010-11-30 22:24:51 UTC
concatenate it with the '1' + pk query

sample



UPDATE table name

SET column name = '1' + num

WHERE conditions



hope this helps
?
2016-05-31 11:09:06 UTC
UPDATE table SET decimalField='0' WHERE decimalField=NULL
Serge M
2010-12-01 09:00:45 UTC
update YourTable

set id = cast('1'+cast(id as varchar) as int)
TheMadProfessor
2010-12-01 06:31:47 UTC
Depends on whether ID is defined as a number or as varchar. If a number and all the existing values are less than 1000, it's pretty simple



UPDATE someTable SET ID = ID + 1000



If it's varchar, syntax will be DBMS dependent but likely one of the following



UPDATE someTable SET ID = '1' + ID

UPDATE someTable SET ID = '1' || ID

UPDATE someTable SET ID = CONCAT('1,' ID)



Note that irregardless of the type and DBMS, if the column is used as a foreign key in other tables, you will not be able to change the value unless the referential integrity rule is set to UPDATE CASCADE.
anonymous
2010-11-30 22:23:49 UTC
UPDATE table_name SET column_name='1300', '1100', '1400', '1123', '1540' WHERE column_name='300', '100', '400', '123', '540';
Waseem
2010-12-02 19:00:43 UTC
Try to run the following code:



update [table name]

set [column name] = '1'+[column name]

where [condition if any]


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...