Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 insert and update stored procedure question

Author  Topic 

gloeffler
Starting Member

1 Post

Posted - 2011-05-04 : 21:50:57
Hello,
1st time posting here, and pretty new to SQL. I am working on a final project and I can't seem to figure out how to accomplish something. I have a table called margin, which has a column named profit in it. It is a computed column using the (sales_price - item_cost) formula. I am trying to write a script that will allow the user to enter 0 for the profit column, and then have the script update that value to whatever the profit calculation turns out to be. Below I have attached my script so far. It doesn't work, and I know it has something to do with the update command after the insert script runs. Any help on this would be helpful.

create or replace procedure add_margin (i_item_num in margin.item_num%type,i_item_cost in margin.item_cost%type,i_sales_price in margin.sales_price%type,i_profit in margin.profit%type) as

begin
insert into margin
values
(i_item_num,i_item_cost,i_sales_price,i_profit);

update margin
set profit = (i_sales_price - i_item cost);

end;
/

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-05-04 : 21:59:15
As a rule we don't answer exam or homework questions on SQLTeam. Sorry.

Also, we're a Microsoft SQL Server site, and it looks like you're using Oracle. It's not a significant difference but it's not exactly the same.

There's an Oracle forum that might be able to help at http://dbforums.com/
Go to Top of Page
   

- Advertisement -