0

i want to copy the content of one column to another column. The copied content should be linked to a string.

|  company  |  new_company  |
_____________________________
Google      | The Google Company

Here the "The" and "Company" are attached as a string to the content.

I have tried a lot, which is the most meaningful to me looks like:

INSERT INTO table_name (copy_into_column)
SELECT CONCAT('The ', copy_from_column, ' Company')
FROM table_name

But with this sql i get that error:

#1292 - Incorrect datetime value: '0000-00-00 00:00:00' for column 'time' at row 1035

Of course, I have several columns in my right table, but actually should be disregarded or?

I hope someone has an idea.

Dieter Information
  • 1,045
  • 2
  • 8
  • 13

2 Answers2

0

Looks like there is another column named time that does not accept null values. You can try inserting current time instead, e.g.:

INSERT INTO table_name (copy_into_column, time)
    SELECT CONCAT('The ', copy_from_column, ' Company'), NOW()
    FROM table_name;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102
0

Aren't you looking for update statement?

UPDATE table_name
SET copycol = CONCAT('The ', copy_from_column, ' Company')

About the error that you get:

You have a timestamp field that apparently is required. from the code you've shared, I see that you are inserting new rows into DB, where I guess you don't fill the other columns.

Ashkan S
  • 10,464
  • 6
  • 51
  • 80