Topics Topics Help/Instructions Help Edit Profile Profile Member List Register Paatha Gnyapakaalu - Archives from Old DB  
Search New Posts 1 | 2 | 8 Hours Search New Posts 1 | 3 | 7 Days Search Search Tree View Tree View Latest tweets Live Tweets   Hide Images

Rate this post by selecting a number. 1 is the worst and 5 is the best.

    (Worst)    1    2    3    4    5     (Best)

Author Message
Top of pagePrevious messageNext messageBottom of page Link to this message

Blazewada
Mudiripoyina Bewarse
Username: Blazewada

Post Number: 24708
Registered: 08-2008
Posted From: 183.90.116.212

Rating: N/A
Votes: 0

Posted on Thursday, October 15, 2015 - 10:47 am:   


Krishna_jilla:




CREATE PROCEDURE libname.UPSERT_MYTABLE (
IN THEKEY DECIMAL(9,0),
IN NEWVALUE CHAR(10) )
LANGUAGE SQL
MODIFIES SQL DATA

BEGIN

DECLARE FOUND CHAR(1);

-- Set FOUND to 'Y' if the key is found, 'N' if not.
-- (Perhaps there's a more direct way to do it.)
SET FOUND = 'N';
SELECT 'Y' INTO FOUND
FROM SYSIBM.SYSDUMMY1
WHERE EXISTS
(SELECT * FROM MYTABLE WHERE KEY = THEKEY);

IF FOUND = 'Y' THEN

UPDATE MYTABLE
SET VALUE = NEWVALUE
WHERE KEY = THEKEY;

ELSE

INSERT INTO MYTABLE
(KEY, VALUE)
VALUES
(THEKEY, NEWVALUE);

END IF;

END;

Topics | Last Hour | Last Day | Last Week | Tree View | Search | Help/Instructions | Program Credits Administration