473,396 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

want to update records of 2nd table when i insert values in 1st table

5
hello
I am facing a problem.
i have two tables named "BILL_DETAIL" and "COMPANY"
both structure is as follws:
---------------------
"BILL_DETAIL"
---------------------
BILL_ID NOT NULL NUMBER(38)
S_HEAD_CODE NOT NULL VARCHAR2(12)
SR_NO NOT NULL NUMBER(38)
BILL_AMOUNT NUMBER(38)
DESCRIPTION NOT NULL VARCHAR2(1000)
CATEGORY_CODE NUMBER(38)
COMP_ID NUMBER(38)
TAX_AMOUNT NUMBER(38)
TAX_ID NUMBER(38)
--------------------------------------------------------
"COMPANY"
--------------------------------------------------------
Name Null? Type
------------------------------- -------- ----
COMP_ID NOT NULL NUMBER(38)
COMP_NAME NOT NULL VARCHAR2(40)
CONTACT_PERSON VARCHAR2(25)
COMP_ADDRESS VARCHAR2(200)
NTN VARCHAR2(15)
OWNER_CNIC VARCHAR2(15)
TOTAL_AMOUNT_PURCHASE NUMBER(38)
TOTAL_AMOUNT_REPAIR NUMBER(38)
------------------------------------------------

I want that when i insert values in "BILL_DETAIL" table and save record. then the BILL_AMOUNT should also be updated in the "COMPANY" table's fields "TOTAL_AMOUNT_PURCHASE" or "TOTAL_AMOUNT_REPAIR"
Please tell me which trigger i should use and at what level with what code

I will be very thankful.

Thanks n regards
Nov 22 '06 #1
1 1758
pragatiswain
96 Expert
--ASSUMPTIONS:
--1. IN BILL_DETAIL, S_HEAD_CODE SIGNIFIES, IF IT IS A PURCHASE OR REPAIR.
--2. IN BILL_DETAIL TOTAL AMOUNT = BILL_AMOUNT + TAX_AMOUNT
--THE AVOBE ASSUMPTIONS WERE MADE AS THE INFORMATION PROVIDED WAS INADEQUATE.

CREATE OR REPLACE TRIGGER TRG_INS_BILL_DETAIL
AFTER INSERT
ON BILL_DETAIL
FOR EACH ROW
BEGIN
IF (:NEW.S_HEAD_CODE IN (<SPECIFY S_HEAD_CODE VALUES FOR PURCHASE>)) THEN
UPDATE COMPANY
SET TOTAL_AMOUNT_PURCHASE = TOTAL_AMOUNT_PURCHASE + :NEW.BILL_AMOUNT + :NEW.TAX_AMOUNT
WHERE COMP_ID = :NEW.COMP_ID ;
ELSE
UPDATE COMPANY
SET TOTAL_AMOUNT_REPAIR = TOTAL_AMOUNT_REPAIR + :NEW.BILL_AMOUNT + :NEW.TAX_AMOUNT
WHERE COMP_ID = :NEW.COMP_ID ;
END TRG_INS_BILL_DETAIL;


Hope this helps.
Nov 22 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
4
by: Rustam Bogubaev | last post by:
Hi, I have a table with the following columns: ID INTEGEDR, Name VARCHAR(32), Surname VARCHAR(32), GroupID INTEGER, SubGroupOneID INTEGER, SubGroupTwoID...
8
by: Jan van Veldhuizen | last post by:
The UPDATE table FROM syntax is not supported by Oracle. I am looking for a syntax that is understood by both Oracle and SqlServer. Example: Table1: id name city ...
1
by: shottarum | last post by:
I currently have 2 tables as follows: CREATE TABLE . ( mhan8 int, mhac02 varchar(5), mhmot varchar(5), mhupmj int )
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
2
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
9
by: joun | last post by:
Hi all, i'm using this code to insert records into an Access table from asp.net, using a stored procedure, called qry_InsertData: PARAMETERS Long, Long, Text(20), Long, DateTime; INSERT...
0
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database...
19
by: eric.nave | last post by:
this is a slight change to a fequently asked question around here. I have a table which contains a "sortorder" column where a user can specify some arbitrary order for records to be displayed in. ...
4
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.