Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8451

Re: INSERT into table A based on SELECT from table B

$
0
0

Hello Dave,

 

No, you don't need VALUES if you use the INSERT...SELECT.. syntax as the inserting values are provided from the select. If you use the values syntax you are going to supply the data 'by hand', usually from literals or variables.

 

It depends on the shape of the pear but you could try something along the lines of....

 

BEGIN

DECLARE varSaveCode INTEGER;

INSERT INTO A_Sales_Ledger(xxx, yyyy, Customer_ID)

SELECT xxx, yyy, Customer_ID FROM Customers WHERE Cust_Name LIKE '%Unique String%';

SET varSaveCode = SQLCode;

IF varSaveCode <> 0 THEN

     -- Some appropriate error handling, maybe....

     MESSAGE 'Oops - a Nashi happened, code '||varSaveCode TO CONSOLE;

     ROLLBACK;

ELSE

     COMMIT;

END IF;

END

-- NB, untested code - I think MESSAGE can cope with the mix of types


(You could try MESSAGE to CLIENT - it depends on the ability of your client software to trap the message.)


HTH, Paul


Viewing all articles
Browse latest Browse all 8451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>