0

So, i have to migrate some data, the query is:

SELECT * FROM ldf.vin_EntePublicoLDF WHERE ejr_id = 2019;

and i have to take those data but set "2020" I try with:

SET vin_EntePublicoLDF.ejr_id = 2020
INSERT INTO ldf.vin_EntePublicoLDF
SELECT * FROM ldf.vin_EntePublicoLDF WHERE vin_EntePublicoLDF.ejr_id = 2019;`

But i recive an error:

[Err] 1193 - Unknown system variable 'ejr_id'

Any suggestion ?

Eric Brandt
  • 7,886
  • 3
  • 18
  • 35
JUAN GB
  • 3
  • 2

2 Answers2

0

If you are trying to update the data, use update:

update ldf.vin_EntePublicoLDF 
    set ejr_id = 2020
    where ejr_id = 2019;

If you want to insert new rows:

INSERT INTO ldf.vin_EntePublicoLDF ( . . ., ejr_id )  -- list columns here
    SELECT . . ., 2020
    FROM ldf.vin_EntePublicoLDF
    WHERE ejr_id = 2019;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

If I'm reading this correctly, you want to create a duplicate set of rows in your table, and change the date for the newly created rows.

To do that, you can SELECT the rows you are interested in, but hard code the value you need to change.

INSERT INTO ldf.vin_EntePublicoLDF
(
  <List of all columns, with ejr_id listed last>
)
SELECT 
  <List of all columns EXCEPT ejr_id>,
  2020 AS ejr_id --<--- Hard-code your year column here.
FROM ldf.vin_EntePublicoLDF 
WHERE ejr_id = 2019;

I moved ejr_id to the end of both column lists to make it easy to find. You could, though, leave it in whatever order it appears in, and just be sure to substitute your hard coded value in the SELECT clause of the INSERT statement.

Eric Brandt
  • 7,886
  • 3
  • 18
  • 35