Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CASE STATEMENT WITHIN A SELECT HAVING A SELECT

Posted on 2004-08-26
6
Medium Priority
?
14,037 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 1000 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 1000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

660 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