Solved

Need Help-Selecting specific rows to update

Posted on 2004-09-22
3
451 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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…

752 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