Solved

CASE STATEMENT WITHIN A SELECT HAVING A SELECT

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

17 Experts available now in Live!

Get 1:1 Help Now