Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DB2 SQL - CASE and TRANSLATE

Posted on 2011-02-18
5
Medium Priority
?
1,225 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

715 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