DB2 - Problemas con update

 
Vista:

Problemas con update

Publicado por ivan (1 intervención) el 17/08/2006 20:11:55
Buenas a todos, soy nuevo trabajando con DB2.
Necesito realizar una actualización de una tabla (HISTORY) que extrae los datos de otra (MAPING). He creado un procedimiento para tratar de hacer esta actualización al ejectarlo me da algunos errores como el siguiente:

DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "END-OF-STATEMENT" was found following "ECLARE
CLIENT_ID INT". Expected tokens may include: "<psm_semicolon>". LINE
NUMBER=4. SQLSTATE=42601
-------------------------------------------------------------------------------
CREATE PROCEDURE MEDIAN_RESULT_SET ()
LANGUAGE SQL
BEGIN
DECLARE CLIENT_ID INT DEFAULT 0;
DECLARE MAPPED_CLIENTID INT;

DECLARE c1 CURSOR FOR
SET CLIENT_ID = (SELECT CLIENTID
FROM MAPING
WHERE STATUSID = 3 AND
MAPPEDCLIENTID != CLIENTID);
SET MAPPED_CLIENTID = (SELECT MAPPEDCLIENTID
FROM MAPING
WHERE CLIENTID = CLIENT_ID);
OPEN c1;
UPDATE HISTORY SET TIMESTAMP = CURRENT TIMESTAMP, ISMERGED = 1,CLIENTID = MAPPED_CLIENTID
WHERE CLIENTID = CLIENT_ID;
CLOSE c1;
END
También he realizado el siguiente statement, pero pide un " ( "

SQL0104N An unexpected token "mappedclientid" was found following "STORY set
clientid =". Expected tokens may include: "(". SQLSTATE=42601

update eis.cli_history set clientid = mappedclientid
from history as a join maping on a.clientid = b.clientid and
a.clientid != a.mappedclientid and
a.statusid = 3 and
a.clientid = 1280957

Y si lo hago de la siguiente manera. Me actualiza toda la tabla.
update history set CLIENTID = (SELECT MAPPEDCLIENTID
from history AS a inner join maping AS b on a.clientid = b.clientid AND
b.statusid = 3 and
b.clientid != b.mappedclientid)

Y lo que necesito es que me actualize el campo SET HISTORY.CLIENTID = MAPING.MAPPEDCLIENTID con las condiciones
maping.clientid != maping.mappedclientid and
maping.statusid = 3 and
maping.clientid = 1280957

Mil gracias de antemano, les agradeciria si alguién saba como hacerlo me responda en cuanto pueda ya que tengo me urge.

De nuevo gracias y saludos

Iván
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder