I need to update a field in table, using data from another table. The second table will have the old field value and the new field value.
Can this be don with a single UPDATE command, or is a procedure required?
I have written a procedure, but get an error on a DECLARE STATEMENT (Invalid syntax).
The error is on the DECLARE CURSOR statement, below.
I am new to SQL. I would appreciate any assistance.
begin
declare newinvfile cursor for
select "old inventory number", "new inventory number", "description"
from "new inventory"
order by "old inventory number";
declare oldinv char(12);
declare newinv char(12);
declare desc char(50);
open newinvfile;
fetch first from newinvfile into OLDINV, NEWINV, DESC;
while (SQLSTATE <> '02000')
update "base inventory" b
set b."inventory number" = newinv
where b."inventory number" = oldinv;
fetch next from newinvfile into oldinv, newinv, desc;
end while;
end
Can this be don with a single UPDATE command, or is a procedure required?
I have written a procedure, but get an error on a DECLARE STATEMENT (Invalid syntax).
The error is on the DECLARE CURSOR statement, below.
I am new to SQL. I would appreciate any assistance.
begin
declare newinvfile cursor for
select "old inventory number", "new inventory number", "description"
from "new inventory"
order by "old inventory number";
declare oldinv char(12);
declare newinv char(12);
declare desc char(50);
open newinvfile;
fetch first from newinvfile into OLDINV, NEWINV, DESC;
while (SQLSTATE <> '02000')
update "base inventory" b
set b."inventory number" = newinv
where b."inventory number" = oldinv;
fetch next from newinvfile into oldinv, newinv, desc;
end while;
end