473,469 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

CASE problem

Hi ,
My table has this layout :

tab.a, tab.b, tab.c, tab.x, tab.y

I want to do this :

when tab.c=0, select tab.x, else select tab.y

The resultset should thus be : a, b and either x or y
This is what I tried :

SELECT table.a,table.b, CASE table.c WHEN '0' THEN table.x ELSE table.y

It doesn't work.

tia

Ward
ps: iseries, V5R1
Nov 12 '05 #1
2 2739
Ward <ki************@for.president.com> wrote:
Hi ,
My table has this layout :

tab.a, tab.b, tab.c, tab.x, tab.y

I want to do this :

when tab.c=0, select tab.x, else select tab.y

The resultset should thus be : a, b and either x or y
This is what I tried :

SELECT table.a,table.b, CASE table.c WHEN '0' THEN table.x ELSE table.y

It doesn't work.


What does "it doesn't work" mean? What's the error message you got?

There is an "END" missing to complete the CASE expression, and you don't
have a FROM clause in your statement.

What are the data types for the columns 'x' and 'y'?

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #2
Knut Stolze <st****@de.ibm.com> wrote in
news:br**********@fsuj29.rz.uni-jena.de:
Ward <ki************@for.president.com> wrote:
Hi ,
My table has this layout :

tab.a, tab.b, tab.c, tab.x, tab.y

I want to do this :

when tab.c=0, select tab.x, else select tab.y

The resultset should thus be : a, b and either x or y
This is what I tried :

SELECT table.a,table.b, CASE table.c WHEN '0' THEN table.x ELSE
table.y

It doesn't work.


What does "it doesn't work" mean? What's the error message you got?

There is an "END" missing to complete the CASE expression, and you
don't have a FROM clause in your statement.

What are the data types for the columns 'x' and 'y'?


Thx for your reply, I neglected the END statement and there were some
quoting/comma issues as well. The query below gave me my resultset..

Cool thing this CASE statement, you can use it wherever you want in the
SELECT part, and then continue selecting other fields. Thx again.

SELECT BRPSIH.SHMAGC, BRPSIH.SHLREG, BRPSIH.SHREGC, BRPSIH.SHINVD,
BRPSIH.SHSIHN, BRPSID.SDEXOR, BRPSDA.SASKLT, BRPNAM.NMA15A,
BRPNAM.NMNAME, BRPSDA.SAWFSQ, BRPSDA.SAOFCN, BRPPRD.PRPDGR,
BRPPRD.PRCAT1, BRPPRD.PRCAT2, BRPPRD.PRCAT3, BRPSDA.SAPRDC,
BRPSDA.SADESN, BRPSDA.SASVCH, BRPSDA.SASVNP, CASE BRPSDA.SAOFCN WHEN 0
THEN BRPSDA.SAAKPN ELSE BRPSDA.SAAKPL END, BRPSDA.SATPLE, SASVCH*SASVNP

FROM ****.BRIC01.BRPNAM BRPNAM, ****.BRIC01.BRPPRD BRPPRD,
****.BRIC01.BRPSDA BRPSDA, ****.BRIC01.BRPSIH BRPSIH, ****.BRIC01.BRPSID
BRPSID

WHERE BRPSIH.SHSIHN = BRPSDA.SASIHN AND BRPSDA.SASIHN = BRPSID.SDSIHN
AND BRPSDA.SASIDS = BRPSID.SDSIDS AND BRPSDA.SAPRDC = BRPPRD.PRPRDC AND
BRPSIH.SHNAMC = BRPNAM.NMNAMC AND ((BRPSIH.SHINVD>=20030101 AND
BRPSIH.SHINVD<=20030115))


Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ryan | last post by:
I'm struggling with a Case statement. The problem I has is with doing >= I can use any value in there, but need to check if it's greater or equal to 1. I'm sure I'm missing something but can't...
1
by: richasaraf | last post by:
Hello everyone, I'm facing problem in converting CASE statements into DECODE. As i have PL/SQL 8i, so it does not handle CASE statements. Please send me the solutions . Then basic problem is the...
0
by: richasaraf | last post by:
Hello everyone, Please HELP !!!!! I'm facing problem in converting CASE statements into DECODE. As i have PL/SQL 8i, so it does not handle CASE statements. Please send me the solutions . Then...
10
by: MLH | last post by:
Suppose the following... Dim A as Date A=#7/24/2005# I wish to compare value of A against 2 other values: 1) 8/1/2005 2) 9/1/2005 Which is better and why... First:
29
by: SysSpider | last post by:
Hi again, This is my problem: when i try to compile the code that contains the function below, i get this: -- gcc:21: error: case label does not reduce to an integer constant gcc:24: error:...
10
by: Chih-Hsu Yen | last post by:
I encountered a strange problem about switch-case statement. switch(cmd) { case 1: statements; break; case 2: statements; break; ... .... case 11: S1; S2; S3; statements;
4
by: jimdscudder | last post by:
I am using a file watcher to watch for files changing. My problem is: the string file info returned is all LOWER CASE. Below is the important part of the code? Any suggestions? using...
8
by: Chris Noble | last post by:
I need to check whether a particular user is already a member of an Active Directory Security Group. The following code extract works but only if the user distinguished name is exactly the same...
9
by: Robbie Hatley | last post by:
Greetings, group. I just found a weird problem in a program where a variable declared in a {block} after a "case" keyword was being treated as having value 0 even though its actual value should...
11
by: Rafe | last post by:
Hi, I'm working within an application (making a lot of wrappers), but the application is not case sensitive. For example, Typing obj.name, obj.Name, or even object.naMe is all fine (as far as...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.