Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 14104
  • Last Modified:

CASE STATEMENT WITHIN A SELECT HAVING A SELECT

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
itssreekant
Asked:
itssreekant
  • 2
2 Solutions
 
dbms_chuCommented:
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
 
BigSchmuhCommented:
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
 
BigSchmuhCommented:
I thought my answer regarding scalar fullselect was explaining the topics...
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now