473,394 Members | 1,916 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,394 software developers and data experts.

Problem in deleteing record based

I have two tables named as “COMPANY and BILL_DETAIL” with the following structure.

BILL_DETAIL TABLE

Name Type Nullable
------------- -------------- --------
BILL_ID NUMBER(7)
S_HEAD_CODE VARCHAR2(12)
SR_NO NUMBER(9)
BILL_AMOUNT NUMBER(10) Y
DESCRIPTION VARCHAR2(1000)
CATEGORY_CODE NUMBER(6) Y
COMP_ID (Foreign Key) NUMBER(9) Y
TAX_AMOUNT NUMBER(9) Y
TAX_ID NUMBER(9) Y


COMPANY TABLE

Name Type Nullable
----------------------- ------------- --------
COMP_ID(PRIMARY Key) NUMBER(9)
COMP_NAME VARCHAR2(40)
CONTACT_PERSON VARCHAR2(25) Y
COMP_ADDRESS VARCHAR2(200) Y
NTN VARCHAR2(15) Y
OWNER_CNIC VARCHAR2(15) Y
TOTAL_BUSINESS_PURCHASE INTEGER Y
TOTAL_BUSINESS_REPAIR INTEGER Y


I am updating COMPANY table whenever I insert values in BILL_DETAIL Table. The following code is working well in solving this problem.

CODE IS AS FOLLOWS:

/*
** CODE WRITTEN TO UPDATE COMPANY BUSINESS RECORD
*/

BEGIN

IF :SUB_HEAD.S_HEAD_CODE IN ('A13001','A13101') THEN

UPDATE COMPANY

SET TOTAL_BUSINESS_PURCHASE = TOTAL_BUSINESS_PURCHASE + :BILL_DETAIL.BILL_AMOUNT
WHERE COMPANY.COMP_ID = :BILL_DETAIL.COMP_ID ;

ELSE IF :SUB_HEAD.S_HEAD_CODE IN ('A13201','A13801') THEN

UPDATE COMPANY
SET TOTAL_BUSINESS_REPAIR = TOTAL_BUSINESS_REPAIR + :BILL_DETAIL.BILL_AMOUNT
WHERE COMP_ID = :BILL_DETAIL.COMP_ID ;

END IF;
END IF;


END;


----------------------------------------------------------------------

/*
** CODE WRITTEN TO DEDUCT TAX AMOUNT FROM COMPANIES BUSINESS
*/

DECLARE

COMPAMOUNT NUMBER;--variable to hold concerened company business (PURCHASE or REPAIR)
SEALAMOUNT NUMBER;--variable to hold the sealing amount from TAX_RULES table
PERCENTAGE NUMBER;--variable to hold the percentage of TAX from TAX_RULES table

-- CODE FOR CAPTURING COMPANIES PURCHASE & REPAIR RECORD

BEGIN

IF :SUB_HEAD.S_HEAD_CODE IN ('A13001','A13101') THEN

SELECT TOTAL_BUSINESS_PURCHASE INTO COMPAMOUNT FROM COMPANY
WHERE COMPANY.COMP_ID=:BILL_DETAIL.COMP_ID;


ELSE
IF :SUB_HEAD.S_HEAD_CODE IN ('A13201','A13801') THEN

SELECT TOTAL_BUSINESS_REPAIR INTO COMPAMOUNT FROM COMPANY
WHERE COMPANY.COMP_ID=:BILL_DETAIL.COMP_ID;

END IF;

END IF;

--CODE TO CAPTURE SEALING AMOUNT & TAX PERCENTAGE FROM TAX_RULES RECORD


SELECT max(nvl(SEALING_AMOUNT,0)),max(nvl(TAX_PERCENTAGE, 0)) INTO SEALAMOUNT,PERCENTAGE FROM TAX_RULES
WHERE TAX_RULES.S_HEAD_CODE=:BILL_DETAIL.S_HEAD_CODE
AND TAX_RULES.TAX_ID=:BILL_DETAIL.TAX_ID;


IF COMPAMOUNT>=SEALAMOUNT --CHECKS IF COMPANY BUSINESS EXCEEDS THAN SEALING AMOUNT
--IF SO, THEN APPLY THE BELOW UPDATE STATEMENT


THEN
UPDATE BILL_DETAIL
SET TAX_AMOUNT=BILL_AMOUNT*(PERCENTAGE/100)
WHERE BILL_DETAIL.COMP_ID=:COMP_ID;


END IF;

END;

Now, I want that when I delete a record from BILL_DETAIL Table then that record should be deleted from company table also.
Please help me in solving this problem.
thanks
Dec 23 '06 #1
2 1103
zalan
6
hi bro use CASCADE option it is used to delete rows with dependanies with rows of tother table hpe this will solve ur prob..
take care
Dec 28 '06 #2
suvam
31
On delete cascade option works on Parent -> child Record deletion . But here I think the reqmt. is opposite .
So u may go for a After Update for each row Trigger of delete statement on table Bill_Detail and delete with Comp_id = :old.comp_id condn.
Jan 2 '07 #3

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

Similar topics

3
by: Steven Stewart | last post by:
Hi there, I have posted about this before, but yet to arrive at a solution. I am going to try to explain this better. I have an Employees table and a Datarecords table (one-to-many...
5
by: b b | last post by:
I created the following code to delete all linked tables in my database (Access 200): -------------------------------------------------------- Dim tbl As TableDef Dim dbs As Database Set dbs...
1
by: kkrizl | last post by:
I have a form that displays general information about an alarm permit location. There's a subform that shows detailed information about burglar alarms that have gone off at the location. When a...
4
by: Prabhat | last post by:
How do I lock a particular record that one user has opened for editing? If I use the pessimistic type, can other users view the record (but not edit it) and return a message telling that another...
5
by: Brad Baker | last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL database. At the top of the page I have the following code: <%@ Page Language="C#" Debug="true" %> <%@ import...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
1
by: zeeshansohail | last post by:
I have two tables named as “COMPANY and BILL_DETAIL” with the following structure. BILL_DETAIL TABLE Name Type Nullable ------------- -------------- -------- ...
6
by: Nick Keighley | last post by:
Hi, Is this code fundamentally broken? class B { } class D: public B {
1
by: tonylove42 | last post by:
HI, I have probelm adding, updating and deleteing a record. Here is my code for adding . The error I get is: Operation must use an updateable query. Line 135: MyCmd.ExecuteNonQuery() ...
43
by: John | last post by:
Hi This .net is driving me crazy!! In VB6 I had a type which contained a couple of multi-dimentional arrays which i used to create and read records: Type AAA : Array1(10,10,2) as Integer
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.