Solved

CASE STATEMENT WITHIN A SELECT HAVING A SELECT

Posted on 2004-08-26
6
13,978 Views
Last Modified: 2012-08-13
Well the question looks complicated actually is it possible to have a select within a case which is a part of select thats my question.


Select field a, field b
             CASE                                      
                WHEN A.MOB_NTWK_TYP_CDE='GSM'    and b.Date>=current date        
                 THEN   (select b.val from tablea ,tableb where a.no=b.no and a.date=b.date)
         END        
AS     "fieldc"        
from
   tablea,tableb,tablec
where
conditions

so is it possible to have this select with the case statement early response is highly appreciated.
regards            
                                   
0
Comment
Question by:itssreekant
[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
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
dbms_chu earned 250 total points
ID: 11911436
I am running db2 v8.  It is possible to have a CASE statement in your select statement.  Here is a simple example that you can run on your system:
select case
              when creator='SYSSTAT' then (select 'xxx' from sysibm.sysdummy1)
              else creator
            end case,
            name
from sysibm.systables


Regarding your second question: "so is it possible to have this select with the case statement ..."
I could not follow your correllation id's.  At first glance, it looks  like you would get syntax errors related to the correllation id's.  


dbms_chu
0
 
LVL 18

Assisted Solution

by:BigSchmuh
BigSchmuh earned 250 total points
ID: 11915186
Having a SELECT in the SELECT clause is named a "Scalar FullSelect" whatever it is embedded in an expression or not.
A "Scalar FullSelect" is a classical SELECT which has to return 0 or 1 row only
According to DB2 SQL Reference guide, you can use it but remenber it has to return 0 or 1 row
==> May be if you post what you really want to answer to we may be of any help. For information, you can almost always transform the syntax (not the results) of a query for it to avoid a SELECT in the SELECT (using GROUP BY or classical table subselect)

Hope this helps.
0
 
LVL 18

Expert Comment

by:BigSchmuh
ID: 12295855
I thought my answer regarding scalar fullselect was explaining the topics...
0

Featured Post

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

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 (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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

615 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