I want to copy the rows of a table OLD
into another table NEW
.
INSERT INTO NEW
SELECT date, kind, id, product, version, quantity FROM OLD;
The table OLD
has a column kind
which is VARCHAR
and contains words like insert
, extract
, delete
. In the NEW
table this column is an INTEGER
. Is there a way to say that if you find delete
insert 1, if you find extract
insert 2 etc.. ?
You can use a CASE
statement to replace the string labels with integers:
INSERT INTO NEW
SELECT date,
CASE WHEN kind = 'delete' THEN 1
WHEN kind = 'extract' THEN 2
ELSE ...
END,
product,
version,
quantity
FROM OLD;
This assumes that the columns line up correctly, and all the other column types match.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments