Solved

DB2 SQL - CASE and TRANSLATE

Posted on 2011-02-18
5
1,215 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
[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
  • 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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