Solved

Need Help-Selecting specific rows to update

Posted on 2004-09-22
3
445 Views
Last Modified: 2006-11-17
Below is a Oracle 9i PL/SQL statements I am trying to run.  I am receiving an ORA-00933 error (SQL command not properly ended).  
============================================================================
These are the tables invovled:

CREATE TABLE PRISMM.DOCRELATION
(
  DOCRELATION_PK    NUMBER(10),
  DOCPARENTNAME    VARCHAR2(30 BYTE),
  DOCPARENT             NUMBER(10),
  DOCCHILDNAME       VARCHAR2(30 BYTE),
  DOCCHILD                NUMBER(10)
)


CREATE TABLE PRISMQ.RESERVATION
(
  RESERVATION_PK                          NUMBER(10),
  ROOMSTAYRESERVATION              VARCHAR2(10 BYTE),
  CONFIRMATIONID                          VARCHAR2(20 BYTE),
  RESERVATIONID                            VARCHAR2(20 BYTE),
  RESERVATIONORIGINATORCODE   VARCHAR2(10 BYTE),
  ORIGINALBOOKINGDATE                DATE,
  CANCELLATIONID                           VARCHAR2(20 BYTE),
  CANCELORIGINATORCODE             VARCHAR2(10 BYTE),
  CANCELLATIONDATE                      DATE,
  STAYDATERANGE                           DATE,
  RECTYPE                                        VARCHAR2(10 BYTE),
  WEEKNUMBER                                VARCHAR2(40 BYTE),
  ORIGINALUSERID                           VARCHAR2(10 BYTE),
  LASTCHANGEUSERID                      VARCHAR2(10 BYTE),
  LASTCHANGEDATE                         DATE,
  RESERVATION_DBDATE                 DATE,
  RESV_RESCOMMENT_FK                 NUMBER(10),
  RESV_SELECTEDMEMBERSHIP_FK  NUMBER(10),
  RESV_RESGUEST_FK                      NUMBER(10),
  RESV_SPECIALREQUEST_FK           NUMBER(10),
  RESV_SERVICE_FK                         NUMBER(10),
  RESV_ROOMSTAY_FK                    NUMBER(10),
  RESV_PROFILE_FK                         NUMBER(10),
  RESV_HOTELREFERENCE_FK         NUMBER(10),
  RESV_LEGACYPROFILE_FK             NUMBER(10),
  RESV_RESVMARKETING_FK           NUMBER(10)
)

========================================================================
What I am trying to do is to select and update specific rows in table "PRISMQ.RESERVATION" where the
" r. reservation_dbdate" equals to todays date (in mm/dd/yyyy format).  The values stored in the " r.reservation_dbdate" column is in mm/dd/yyyy.

All other rows where the " r.reservation_dbdate" does not equal to todays date I want to dropped it from further processing.

If a row does equal to todays date I then want to further qualify for updating by comparing to  table "prismm.docrelation".

This is done by:

     1.   comparing the value stored in column  "d.docparent" (prismm.docrelation) to "r.reservation_pk "  
           (prismq.reservation)
     2.   d.docparentname equals to "RESERVATION"
     3.   d.docchildname equals to "LEGACYPROFILE"

If any of the above three conditions fails I want to drop the row in "PRISMQ.RESERVATION" from any further update consideration.


Let me know if there is a better way of coding.

Here is the SQL code in question
=========================================================================
UPDATE PRISMQ.RESERVATION r
   SET resv_legacyprofile_fk =
       (SELECT r.reservation_pk  FROM PRISMM.RESERVATION r
           WHERE TRUNC(SYSDATE) = r.reservation_dbdate)
               
 SELECT d.docchild FROM prismm.docrelation d
     WHERE r.reservation_pk  = d.docparent
         AND d.docparentname = 'RESERVATION'
         AND d.DOCCHILDNAME = 'LEGACYPROFILE';
            
COMMIT;




Thanks.
0
Comment
Question by:john1953
3 Comments
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 250 total points
ID: 12129069
"Commit" isn't necessary unless this is part of a multi-transaction stored procedure. Try this:

UPDATE r SET resv_legacyprofile_fk = r.reservation_pk
FROM PRISMQ.RESERVATION r, prismm.docrelation d
WHERE r.reservation_pk  = d.docparent
 AND d.docparentname = 'RESERVATION'
 AND d.DOCCHILDNAME = 'LEGACYPROFILE'
 AND To_Date(SYSDATE, 'mm/dd/yyyy') = To_Date(r.reservation_dbdate, 'mm/dd/yyyy');
0
 

Assisted Solution

by:vijayaja
vijayaja earned 250 total points
ID: 12131337
Hi,

The initial SQL written is in a wrong way to achieve the logic. Since there is an additional select in it without a semicolon it is throwing the error.(Anyways the logic would be wrong)

Also as later mentioned yuo cannot use the FROM clause in the Update statement as written.

Try this piece of code, which I hope it achieves the functionality you are aiming for..

UPDATE PRISMQ.RESERVATION r
   SET R.resv_legacyprofile_fk =
       (SELECT          r1.reservation_pk  
        FROM          PRISMM.RESERVATION r1,
                      prismm.docrelation d       
           WHERE   TRUNC(SYSDATE) = trunc(r1.reservation_dbdate)
             and   r1.reservation_pk  = d.docparent       
             AND   d.docparentname = 'RESERVATION'      
             AND   d.DOCCHILDNAME = 'LEGACYPROFILE'
           and   r1.reservation_pk =r.reservation_pk      )
0
 

Author Comment

by:john1953
ID: 12259982
thanks.  jdlambert1 and vijayaja were a big help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now