How to calculate Stock information?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rohullah
    New Member
    • Mar 2010
    • 43

    How to calculate Stock information?

    Hello Sir

    I have Error with the following tables one is [INCOME] And one is[Stock].

    Income table Columns.
    Date ItemID ItemType Amount DriverName TruckNo
    ---------------------
    Stock Table columns.
    Itemid ItemName ItemType Amount
    -----------------------------------
    Now when i enter record to income table
    and income itemid not = to stock itemid then
    itemid,itemName ,ItemType,Amoun t Should be insert to the Stock table.
    elsif income itemid = to stock itemID then
    the stock the stock table should be update.
    it means that income table amount Should Plus To Stock table amount
    stock.amoutn + income.amount.
    i try the following code but it does not work.
    ---------------------------------
    Code:
    declare
    begin
    if :income.itemid<>:stock.itemid then
    insert into stock(itemid,itemname,itemtype,amount)
    values(:income.itemid,:income.itemname,:income.itemtype,:income.amount);
    		elsif :income.itemid=:stock.itemid then
    		update stock set amount=amount+:income.amount where itemid=:stock.itemid;
    	commit_form;
    		go_block('Income');
    	execute_query;
    go_block('stock');
    Execute_query;
    	end if;
    end;
    -----------------------------------
    Please sir give me the Exact Answer
    Thank you in advance.
    Last edited by debasisdas; Nov 12 '10, 12:21 PM. Reason: Formatted using code tags.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    How the above two mentioned tables are linked ?

    Comment

    • Rohullah
      New Member
      • Mar 2010
      • 43

      #3
      They are not linked,Send me Passible answer Plz.

      Comment

      • amitpatel66
        Recognized Expert Top Contributor
        • Mar 2007
        • 2358

        #4
        This will not work because you are checking the current income.item_id with current stock.item_id.

        You will need to query the stocks table to check if the entry for a particular item_id occurs in stocks table, if not then insert else update.

        Comment

        • Rohullah amiree

          #5
          ok send me the complete sulotion of this problem, I means what is the possible way to solve the problem thanks

          Comment

          • amitpatel66
            Recognized Expert Top Contributor
            • Mar 2007
            • 2358

            #6
            Here is the pseudo code:

            [code=oracle]

            SELECT count(*) into v_cnt from stock where item_id = :income.item_id ;

            IF v_cnt > 0 then

            update stock

            else

            insert into stock values.....

            [/code]

            I hope this helps.

            Comment

            Working...