Solved

DB2 SQL - CASE and TRANSLATE

Posted on 2011-02-18
5
1,208 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
Comment Utility

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
Comment Utility
0
 

Author Comment

by:raheis
Comment Utility
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
Comment Utility
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
Comment Utility
Thx a million
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 (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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now