Article View: borland.public.interbase.sql
Article #127Re: insert into problem
From: Isaac
Date: Sun, 08 Jun 2008 18:47
Date: Sun, 08 Jun 2008 18:47
66 lines
3374 bytes
3374 bytes
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
Technical Details
Message-ID:
<484c2889@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!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>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 21:47:28 +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> In-Reply-To: <484c07a9$1@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: <484c2889@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1212950665 41.234.201.204 (8 Jun 2008 11:44:25 -0700) Lines: 66 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail X-Original-Bytes: 3190