Article View: borland.public.interbase.sql
Article #128Re: insert into problem
From: Isaac
Date: Sun, 08 Jun 2008 20:28
Date: Sun, 08 Jun 2008 20:28
71 lines
3683 bytes
3683 bytes
Isaac wrote: > please also look at my procedure I got a weird problem the first > update is executed normally but the second one never executed !! > although I did the debug work with live numbers > > CREATE PROCEDURE PROC_TRANS_ITEMS ( > p_old_qty float, > p_new_qty float, > p_from_inv_code integer, > p_to_inv_code integer, > p_item_code varchar(25), > p_to_item_code varchar(25)) > as > declare variable v_cur_qty float; > declare variable v_item_name varchar(150) character set win1252; > begin > /* ---------- >>>>>>>> check old onventory first */ > select cur_qty, item_name from inventory_items > where (inventory_items.inv_code = :p_from_inv_code) > and (inventory_items.item_code = :p_item_code) > into :v_cur_qty, :v_item_name; > > if (v_cur_qty is null) then v_cur_qty = 0; > > v_cur_qty = v_cur_qty - p_new_qty + p_old_qty; > if (v_cur_qty < 0) then exception EXCP_BAL_IS_UNDER_ZERO; > > update inventory_items set CUR_QTY = :v_cur_qty > where (inventory_items.inv_code = :p_from_inv_code) > and (inventory_items.item_code = :p_item_code); > > /* -------------->>>>>>>>> check new inventory */ > v_cur_qty = null; > select cur_qty from inventory_items > where (inventory_items.inv_code = :p_to_inv_code) > and (inventory_items.item_code = :p_to_item_code) > into :v_cur_qty; > > if (v_cur_qty is null) then exception EXCP_NO_ITEM_FOUND; > > /*if (v_cur_qty = -1) then begin > v_cur_qty = 0; > > select max(item_code) from inventory_items > where (inventory_items.inv_code = :p_to_inv_code) > and (inventory_items.item_code = :p_to_item_code) > into :v_max_item_code; > > if (v_max_item_code is null) then > v_max_item_code = 1; > else > v_max_item_code = v_max_item_code + 1; > > insert into inventory_items (INV_CODE, ITEM_CODE, ITEM_NAME, CUR_QTY, > MIN_QTY, OB_QTY, OB_TOTAL_COST, UNIT_PRICE, UNIT_COST) > values (:p_to_inv_code, :v_max_item_code, > :v_item_name, :v_cur_qty, 0, 0, 0, 0, 0); > end */ > > v_cur_qty = v_cur_qty + p_new_qty - p_old_qty; > if (v_cur_qty < 0) then exception EXCP_BAL_IS_UNDER_ZERO; > > update inventory_items set CUR_QTY = :v_cur_qty > where (inventory_items.inv_code = :p_to_inv_code) > and (inventory_items.item_code = :p_to_item_code); > > end Is this possible !!!!!!!!!!! I discovered that the problem because I did not made a proper foreign key and after I made one the second update worked !! which make me wonder does the update statement inside a stored procedure need a foreign key to work !!
Technical Details
Message-ID:
<484c4058@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<484b07da@newsgroups.borland.com> <484b16e4@newsgroups.borland.com> <484b52eb$1@newsgroups.borland.com> <484c007f@newsgroups.borland.com> <484c07a9$1@newsgroups.borland.com> <484c2889@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,ed255c09332ecd2c X-Google-Attributes: gid114a0e,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Sun, 08 Jun 2008 23:28:44 +0300 From: Isaac <no@no.com> User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 Newsgroups: borland.public.interbase.sql Subject: Re: insert into problem References: <484b07da@newsgroups.borland.com> <484b16e4@newsgroups.borland.com> <484b52eb$1@newsgroups.borland.com> <484c007f@newsgroups.borland.com> <484c07a9$1@newsgroups.borland.com> <484c2889@newsgroups.borland.com> In-Reply-To: <484c2889@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 41.234.201.204 Message-ID: <484c4058@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1212956760 41.234.201.204 (8 Jun 2008 13:26:00 -0700) Lines: 71 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail