?
Solved

UPDATE statement for copying from one column to another in same table

Posted on 2006-03-30
6
Medium Priority
?
831 Views
Last Modified: 2012-06-21
I have a table which tracks how a task is moving from one approver's queue to another.I have these columns.
RTE_IDFR, RTE_SEQ_NBR , DATE_ASGN, RTE_ACTN_DATE, DATE_AVBL.
for1st aprover RTE_SEQ_NBR will be 1 for 2nd one 2 so on.RTE_IDFR, DATE_ASGN will be same for all approvers of one task.
I want to update date_avbl for 1st approver to be DATE_ASGN and for all subsequent approvers DATE_AVBL should be updated to RTE_ACTN_DATE of previous approver.I have correct RTE_ACTN_DATE for whole table but DATE_AVBL column is all messed up and hence i want this update.
Column descriptions :
 RTE_IDFR                                  NOT NULL NUMBER(10)
 RTE_SEQ_NBR                               NOT NULL NUMBER(5)
 DATE_ASGN                                 NOT NULL DATE
 RTE_ACTN_DATE                                      DATE
 DATE_AVBL                                          DATE
 
0
Comment
Question by:chsrinivas123
  • 4
  • 2
6 Comments
 

Author Comment

by:chsrinivas123
ID: 16336053
Detailed description of my question:
I have a table which tracks how a task is moving from one approver's queue to another.

I have these columns.
RTE_IDFR,
RTE_SEQ_NBR,
DATE_ASGN,
RTE_ACTN_DATE,
DATE_AVBL

For 1st approver RTE_SEQ_NBR will be 1
For 2nd approver RTE_SEQ_NBR will be 2
For 3rd approver RTE_SEQ_NBR will be 3 so on.

RTE_IDFR, DATE_ASGN will be same for all approvers of one task.

I WANT TO WRITE A SQL WHICH DOES MASS UPDATE:

I want to update DATE_AVBL for 1st approver to be DATE_ASGN of 1st approver and for all subsequent approvers DATE_AVBL should be updated to RTE_ACTN_DATE of previous approver.

REASON FOR DOING THIS WHICH YOU MIGHT NOT EVEN CARE: I have correct RTE_ACTN_DATE for whole table but DATE_AVBL column is all messed up and hence i want this update.

Column descriptions :
 RTE_IDFR                                  NOT NULL NUMBER(10)
 RTE_SEQ_NBR                               NOT NULL NUMBER(5)
 DATE_ASGN                                 NOT NULL DATE
 RTE_ACTN_DATE                                      DATE
 DATE_AVBL                                          DATE

ANY HELP WOULD BE REALLY APPRECIATED.
0
 
LVL 19

Expert Comment

by:actonwang
ID: 16336446
Try this:

update
(select * from approve where rte_seq_nbr > 1 order by rte_seq_nbr desc) a
set date_avbl = (select b.rte_actn_date from approve b where b.rte_seq_nbr = a.rte_seq_nbr +1)
/
0
 
LVL 19

Accepted Solution

by:
actonwang earned 500 total points
ID: 16336472
Sorry, it should be:

update
(select * from approve where rte_seq_nbr > 1 order by rte_seq_nbr desc) a
set date_avbl = (select b.rte_actn_date from approve b where b.rte_seq_nbr = a.rte_seq_nbr -1 and b.rte_idfr = a.rte_idfr and b.date_asgn = a.date_asgn )
/
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:actonwang
ID: 16337128
I assume that your table name is "approve"
0
 

Author Comment

by:chsrinivas123
ID: 16337852
Hi  actonwang,
   That virtual table idea worked for me.Thanks a lot!!
0
 
LVL 19

Expert Comment

by:actonwang
ID: 16338727
My pleasure :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question