cancel
Showing results for 
Search instead for 
Did you mean: 

Execute two INSERTS in one stored procedure

0 Kudos
2,744

Hi

I have the following stored procedure

ALTER PROCEDURE dba.jg_x_new_pn @oldpn varchar(25)
AS

BEGIN

DECLARE @newpn varchar(25)
SET @newpn = string('78',dba.getnextprimary('primary_key'))
INSERT INTO dba.table1
SELECT opco_code,@newpn,proddesc,prodcateg,prodsell,discmat,sequence,obsolete,prodcost,replace(memo,'9010','9003'),qtytype,qtydecimal,qtyfactor,allowsplit,stocked,selldecimals,costdecimals,pack,altref1,altref2,altref3,altref4,privatememo,lastupdatedtimestamp,lastupdated,lastupdatedby,created,createdby,allowlinediscount,allowoveralldiscount,allowsettlementdiscount,saleprice,nextprice,salefrom,saleto,nextpricestart,vatcode,unitdescription,purchaseanalysis,salesanalysis,warranty,warrantydefault,defaultwarehouse,unitweight,unitweightdecimals,unitweightdesc,unitvolume,unitvolumedecimals,unitvolumedesc,prodtype,webcatalog,webprodref,webproddesc,webprodextdesc,weballowsplit,hazardsubstance,recipientrecordrequired,datenextavailable,qtyavailable,barcode,parentprodref,variationdesc,specification,sys_a_objects_key,purchasecurrency,purchasecost,purchasecostdecimals,cataloguecode,catalogueref,manufacturer,manufacturerref,templateprodref,isatemplate,binlocation,costcentre,department,webvalidation,deliverychargetype,excludefromoverallpromotion,defaultsupersededby,supersededqtyratio,supersededqtymultiply
FROM dba.table1
WHERE prodref = @oldpn
SELECT @newpn
INSERT INTO dba.table2 (id, prodref, notes)
VALUES (getNextPrimary('primary_key_notes.id'), (SELECT @newpn), 'I MADE THIS')
END
COMMIT;

The first insert command runs fine, but the second INSERT command doesn't do anything. I was expecting it to INSERT a new line into table2 using the new part number (@newpn).

What am I doing wrong?

Accepted Solutions (0)

Answers (0)