Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DB2 SQL - CASE and TRANSLATE

Posted on 2011-02-18
5
Medium Priority
?
1,231 Views
Last Modified: 2012-05-11
Hello,

I neeed some help getting my SQL complete.

Current SQL:
SELECT
CASE WHEN x.num IS NOT NULL THEN 'Y' ELSE TRANSLATE(y.ind,'A','Y')  END
FROM example x, example2 y

Output
IF x.num is not null THEN Returns 'Y'
ELSE IF y.ind = 'Y' THEN Return 'A'

What I need to do is:
IF x.num is not null THEN Returns 'Y'
ELSE IF y.ind = 'Y' THEN Return 'A' ELSE Return 'N'

Thanks,
R.


 
0
Comment
Question by:raheis
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
pdd1lan earned 2000 total points
ID: 34924537

SELECT
CASE
WHEN x.num IS NOT NULL THEN 'Y'
WHEN y.ind = 'Y'   THEN Return 'A'
ELSE Return 'N'
END AS CASE_SAMPLE
FROM example x, example2 y
0
 

Author Comment

by:raheis
ID: 34924619
SELECT
CASE WHEN x.num IS NOT NULL THEN 'Y' WHEN y.ind="Y" THEN 'A' ELSE 'N' END AS case_sample
FROM example x, example2 y

The above gave me an error: SQLSTATE=4260
         CASE WHEN reg.cas_num IS NOT NULL THEN 'Y' WHEN cas.alt_ind="Y" THEN 'A' ELSE 'N' END AS cas_accept_ind,
0
 

Author Comment

by:raheis
ID: 34924638
SELECT        
CASE WHEN x.num IS NOT NULL THEN 'Y' WHEN y.ind='Y' THEN 'A' ELSE 'N' END AS case_sample
FROM example x, example2 y

Worked Thx.
0
 

Author Closing Comment

by:raheis
ID: 34924660
Thx a million
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

916 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