IN operator in SELECT CASE statement

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

IN operator in SELECT CASE statement

Post by naren6876 »

Hi,

The database is DB2.

My requirement is

If the first 6 characters of RECORD_ID = LOC_ID then get the REGION_NAME from LOC_INFO table.

If you are not finding some of the records then fall back would be to compare the first 3 characters.

I wrote a query as below, but erroring out with the following error

Error: SQL0104N An unexpected token "REGION_NAME" was found following "FO) THEN Select". Expected tokens may include: "END". SQLSTATE=42601

(State:42601, Native Code: FFFFFF98)

Query is:
--------------
Select
CASE
WHEN substr(RECORD_ID,1,6) IN (Select LOC_ID From LOC_INFO)
THEN Select REGION_NAME From LOC_INFO;
WHEN substr(RECORD_ID,1,3) IN (Select LOC_ID From LOC_INFO)
THEN Select REGION_NAME From LOC_INFO;
ELSE ' '
END CASE
from RECORD_INFO



Any clue would be much appreciated.

Thanks in advance.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

I don't think the semi-colons within the CASE construct are correct, but it's been some time since I wrote Oracle queries in anger.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply