If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Updating field in one table based on field in another table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-10-12, 18:41
jo15765 jo15765 is offline
Registered User
 
Join Date: Feb 2012
Posts: 20
Updating field in one table based on field in another table

I have been trying to figure out this statement for 3 days now and am no further along than I was Wed!

What I am trying to do is update the value of ActiveStatus in my table Customer based on the value of BillDueDate in my Billing Table. The problem I am having is there is no ForiegnKey to link the two tables together!

here are my tables:
SQL> CREATE TABLE BILLING (
2 BillID NUMBER(5) NOT NULL,
3 CustID NUMBER(5) NOT NULL,
4 BillDate DATE,
5 BillDueDate DATE,
6 BillPaidDate DATE,
7 BillDueAmt NUMBER(5,2),
8 BillPaidAmt NUMBER(5,2),
9 BillStatus VARCHAR2(8),
10 CONSTRAINT BILLING_BILLID_PK PRIMARY KEY (BillID));

SQL> CREATE TABLE CUSTOMER (
2 CustID NUMBER(5) NOT NULL,
3 CustLname VARCHAR2(25),
4 CustFname VARCHAR2(20),
5 CustAddr VARCHAR2(25),
6 CustCity VARCHAR2(25),
7 CustState CHAR(2),
8 CustZip CHAR(5),
9 CustPhone NUMBER(10),
10 CustEmail VARCHAR2(35),
11 CustSDate DATE,
12 CustActiveStatus VARCHAR2(5),
13 EmpID NUMBER(5) NOT NULL,
14 CustInactDate DATE,
15 CustInactReason VARCHAR2(250),
16 CONSTRAINT CUSTOMER_CUSTID_PK PRIMARY KEY (CustID));

I have tried this code, plus numerous variations and I can't seem to get it!
Code:
UPDATE Customer SET CustActiveStatus = 'NO' WHERE BillDueDate IN (Select BillDueDate FROM Billing) WHERE BillDueDate IN ((sysdate-30) > BillDueDate);
I feel like I am almost there, but by George am I not hitting it!
Reply With Quote
  #2 (permalink)  
Old 02-10-12, 19:42
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
consider joining CUSTOMER.CUSTID & BILLING.CUSTID in addition to what you already have
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.

Last edited by anacedent; 02-10-12 at 19:49.
Reply With Quote
  #3 (permalink)  
Old 02-10-12, 19:47
jo15765 jo15765 is offline
Registered User
 
Join Date: Feb 2012
Posts: 20
I tried to execute this:
Code:
UPDATE Customer Set CustActiveStatus = 'No" WHERE CustID IN (Select CustID from Billing WHere sysdate-30 > BillDueDate) INNER JOIN Customer.Custid = Billing.Custid;
And I am getting an ORACLE error of quoted string not properly terminated.
Reply With Quote
  #4 (permalink)  
Old 02-10-12, 19:50
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
single quote marks must be used in pairs
There is no need to used double quote marks.
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #5 (permalink)  
Old 02-10-12, 19:53
jo15765 jo15765 is offline
Registered User
 
Join Date: Feb 2012
Posts: 20
That was a typo, good catch!! Now running the same command I am getting SQL Command not properly ended/
Reply With Quote
  #6 (permalink)  
Old 02-10-12, 19:57
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
how does SQL below work?
Code:
UPDATE customer 
SET    custactivestatus = 'No' 
WHERE  custid IN (SELECT custid 
                  FROM   billing 
                  WHERE  SYSDATE - 30 > billduedate 
                         AND customer.custid = billing.custid)
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #7 (permalink)  
Old 02-10-12, 20:05
jo15765 jo15765 is offline
Registered User
 
Join Date: Feb 2012
Posts: 20
To Perfection! Thank you!


Actually one more change --- I also need to updae my CustInactiveDate to be Date()...how would that be added to the above SQL?

Last edited by jo15765; 02-10-12 at 20:09.
Reply With Quote
  #8 (permalink)  
Old 02-10-12, 20:13
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
SET (custactivestatus,CustInactiveDate) = ('No' ,SYSDATE)
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #9 (permalink)  
Old 02-10-12, 20:16
jo15765 jo15765 is offline
Registered User
 
Join Date: Feb 2012
Posts: 20
Absolutely perfect thank you!

3 days of my work, solved in 30 minutes!!!!! http://www.dbforums.com/db_images_v3...ilies/beer.gif
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On