Solved

DB2 SQL - CASE and TRANSLATE

Posted on 2011-02-18
5
1,212 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 500 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
 
LVL 8

Expert Comment

by:pdd1lan
ID: 34924541
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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