Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SQL insert on a case statement

3635277Feb 7 2018 — edited Feb 12 2018

I am new to SQL (Oracle) and I am trying to write a statement that if Parent1 and Parent2 address is different, then I want Parent2 to insert in the next row with the same student information. The first part (before the CASE statement with the bottom part (FROM, WHERE, GROUP) work by itself but I wanted to being in Parent2 info if it's different from Parent1.

Thanks!

SELECT
  MAX
(STUDENTS.LAST_NAME) AS LASTNAME,
  MAX
(US.GUARDIAN1_FIRSTNAME || ' ' || US.GUARDIAN1_LASTNAME) AS PARENT1,
  MAX
(US.GUARDIAN2_FIRSTNAME || ' ' || US.GUARDIAN2_LASTNAME) AS PARENT2,
  MAX
(US.GUARDIAN1_ADDRESSSTREET) AS PARENTADDRESS

  
CASE
  
WHEN (MAX(US.GUARDIAN1_ADDRESSSTREET) <>  MAX(US.GUARDIAN2_ADDRESSSTREET)
INSERT (MAX(STUDENTS.LAST_NAME) AS LASTNAME,
MAX
(' ' || ' ') AS PARENT1,
MAX
(US.GUARDIAN2_FIRSTNAME || ' ' || US.GUARDIAN2_LASTNAME) AS PARENT2,
MAX
(US.GUARDIAN2_ADDRESSSTREET)

FROM
  STUDENTS
,
  U_STUDENTSUSERFIELDS US
WHERE
  US
.studentsdcid = students.dcid
  
AND STUDENTS.ENROLL_STATUS = 0
  
AND STUDENTS.ENROLLMENT_SCHOOLID = 340
GROUP BY
  STUDENTS
.FAMILY_IDENT

I want it to look like this:

LASTNAMEPARENT1
PARENT2PARENTADDRESS

Smith

Jane DoeJohn Smith1818 Street
SmithJohn Smith

2525 Other Street

JonesAlice JonesMike Jones111 Old Street
JohnsonPerl JohnsonBob Johnson222 Sesame Street
ApplesEddy ApplesSally Apples555 Street
ApplesSally Apples333 Helmme Ave.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 12 2018
Added on Feb 7 2018
5 comments
4,134 views