?
Solved

PL/SQL CASE Statement

Posted on 2009-05-05
3
Medium Priority
?
425 Views
Last Modified: 2013-12-07
I keep getting errors on this.  Can someone help me write this statement correctly?  
Basically, if my first result ends in "0", then I want the first letter of the last name, else I want the last number of the Subscriber ID.


CASE substr(O221762."Subscriber_ID",9,1)
     WHEN "0" THEN  substr(O221762."Mbr_Last_Name",1,1) AS "CM_ID"
     ELSE substr(O221762."Subscriber_ID",9,1) AS "CM_ID"
END

Open in new window

0
Comment
Question by:Luis5011
[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
  • 2
3 Comments
 
LVL 14

Expert Comment

by:ajexpert
ID: 24306765
How abt this?

 CASE substr(O221762.Subscriber_ID,9,1)
     WHEN '0' THEN  substr(O221762.Mbr_Last_Name,1,1) AS "CM_ID"
     ELSE substr(O221762.Subscriber_ID,9,1) AS "CM_ID"
END
 

Open in new window

0
 

Author Comment

by:Luis5011
ID: 24306962
Nope.  Tells me I have a missing key word.
0
 

Accepted Solution

by:
Luis5011 earned 0 total points
ID: 24307115
I figured it out.  I used the following format and added the " " around the field name, which I hadn't done.

CASE
     WHEN substr(O221762."Subscriber_ID",9,1)= 0 THEN  substr(O221762."Mbr_Last_Name",1,1)
     WHEN substr(O221762."Subscriber_ID",9,1)<>0 THEN  substr(O221762."Subscriber_ID",9,1)
END  AS "CM_ID",
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

649 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