Solved

CASE STATEMENT WITHIN A SELECT HAVING A SELECT

Posted on 2004-08-26
6
13,856 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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