473,805 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

case statement

mmm
Hello,

I wrote the following statement:
SELECT CASE
WHEN (SELECT count(*) FROM employee where empno='000010') >0 THEN
'true'
ELSE 'false'
END AS isExist
from employee where empno='000010'

My problem is that when the empno exists everything is ok but when it
does not exist I got no record becuase of the last where cluase.

How can I rewrite this statement in order to get true when exists and
false when it does not exist?

Thanks
Nov 12 '05 #1
4 44653
me******@inter. net.il (mmm) wrote in message news:<95******* *************** ****@posting.go ogle.com>...
Hello,

I wrote the following statement:
SELECT CASE
WHEN (SELECT count(*) FROM employee where empno='000010') >0 THEN
'true'
ELSE 'false'
END AS isExist
from employee where empno='000010'

My problem is that when the empno exists everything is ok but when it
does not exist I got no record becuase of the last where cluase.

How can I rewrite this statement in order to get true when exists and
false when it does not exist?

Thanks


There are a few, but here is one close to what you have:
SELECT CASE
WHEN (SELECT count(*) FROM employee where epmno = '000010') > 0 THEN
'true'
ELSE 'false'
END AS isExist
from sysibm.sysdummy 1;
Nov 12 '05 #2
mmm
jb**********@ae p.com (Jeff) wrote in message news:<15******* *************** ****@posting.go ogle.com>...
me******@inter. net.il (mmm) wrote in message news:<95******* *************** ****@posting.go ogle.com>...
Hello,

I wrote the following statement:
SELECT CASE
WHEN (SELECT count(*) FROM employee where empno='000010') >0 THEN
'true'
ELSE 'false'
END AS isExist
from employee where empno='000010'

My problem is that when the empno exists everything is ok but when it
does not exist I got no record becuase of the last where cluase.

How can I rewrite this statement in order to get true when exists and
false when it does not exist?

Thanks


There are a few, but here is one close to what you have:
SELECT CASE
WHEN (SELECT count(*) FROM employee where epmno = '000010') > 0 THEN
'true'
ELSE 'false'
END AS isExist
from sysibm.sysdummy 1;

Hello,

I am using AS400/DB2 - should it (using the sysibm.sysdummy 1) works
the same as other platforms?

I tried to use the following command and it seems good:

SELECT CASE
WHEN (SELECT count(*) FROM employee where empno='000010') >0 THEN
'true'
ELSE 'false'
END AS isExist
from employee group by 'isExist'

Do you think that using the sysibm.sysdummy 1 view is better for
performance?

Thanks a lot
Nov 12 '05 #3
mmm wrote:
jb**********@ae p.com (Jeff) wrote in message news:<15******* *************** ****@posting.go ogle.com>...
me******@inte r.net.il (mmm) wrote in message news:<95******* *************** ****@posting.go ogle.com>...
Hello,

I wrote the following statement:
SELECT CASE
WHEN (SELECT count(*) FROM employee where empno='000010') >0 THEN
'true'
ELSE 'false'
END AS isExist
from employee where empno='000010'

My problem is that when the empno exists everything is ok but when it
does not exist I got no record becuase of the last where cluase.

How can I rewrite this statement in order to get true when exists and
false when it does not exist?

Thanks


There are a few, but here is one close to what you have:
SELECT CASE
WHEN (SELECT count(*) FROM employee where epmno = '000010') > 0 THEN
'true'
ELSE 'false'
END AS isExist
from sysibm.sysdummy 1;


Hello,

I am using AS400/DB2 - should it (using the sysibm.sysdummy 1) works
the same as other platforms?

I tried to use the following command and it seems good:

SELECT CASE
WHEN (SELECT count(*) FROM employee where empno='000010') >0 THEN
'true'
ELSE 'false'
END AS isExist
from employee group by 'isExist'

Do you think that using the sysibm.sysdummy 1 view is better for
performance?

Thanks a lot


Actually that select will give you as many rows back as there are in the
employee table whcih is not what you want.
I think Db2 for AS/400 supports SYSIBM.SYSDUMMY 1. If it doesn't theer
must be soem other single-row object you can use like VALUES.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #4
SELECT CASE WHEN count(*) > 0 THEN 'true' ELSE 'false' END FROM employee
where empno='000010'

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
14162
by: Joe Stevenson | last post by:
Hi all, I skimmed through the docs for Python, and I did not find anything like a case or switch statement. I assume there is one and that I just missed it. Can someone please point me to the appropriate document, or post an example? I don't relish the idea especially long if-else statements. Joe
6
4704
by: deanfamily11 | last post by:
I've set up a case statement to have my program determine where on the Cartesian plane a point the user enters is located. I keep getting the C2051 error when I compile. Any help? #include <iomanip> #include <iostream> using namespace std;
7
1780
by: Shapper | last post by:
Hello, I have a "Select Case MyVar" in which I define the values of an Array according to the value of MyVar. I need to use the Array Values in a Loop after End Select. It seems the Array is deleted on End Select. How can I make it available for my loop?
3
3402
by: mark.irwin | last post by:
Hello all, Have an issue where a redirect pushes data to a page with a select case which then redirects to another page. Problem is the redirect isnt working in 1 case. Code below: strURL = "" if i = 1 then strURL = "redirect.aspx?page=APIQ&parcel=" & strParcel &
12
21096
by: rAinDeEr | last post by:
Hi, I have a table with 2 columns ** CREATE TABLE test (emp_num DECIMAL(7) NOT NULL,emp_name CHAR(10) NOT NULL) and i have inserted a number of records. ** Now, I want to insert a new record (3232,'Raindeer') based on the condition that the
5
2419
by: Frederick Dean | last post by:
Hi,guys! I'm reading Stephen Dewhurst's book "C++ Gotchas"£¬in gothca #7, I meet a weird case: bool Postorder::next() { switch (pc) case START: while (true) if (!child()) { pc = LEAF; return true;
1
21691
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case "01" : dWarrExpDateMonth="Jan" : dRetailDateMonth="Jan" case "02" : dWarrExpDateMonth="Feb" : dRetailDateMonth="Feb" End Select
22
3182
by: John | last post by:
Hi Folks, I'm experimenting a little with creating a custom CEdit control so that I can decide on what the user is allowed to type into the control. I started off only allowing floating point numbers then added support for putting in lat/lon coordinates. I tried this little piece of code inside the OnChar function but compiler complained about missing ';' after "case _T('W'):"
9
2116
by: Robbie Hatley | last post by:
Greetings, group. I just found a weird problem in a program where a variable declared in a {block} after a "case" keyword was being treated as having value 0 even though its actual value should have been something else. An extremely stripped-down version: int Function (int something) { switch(something) { case WHATEVER:
13
11863
by: Satya | last post by:
Hi everyone, This is the first time iam posting excuse me if iam making any mistake. My question is iam using a switch case statement in which i have around 100 case statements to compare. so just curious to find out is it effective to use this method?? or is there is any other alternative method present so that execution time and code size can be reduced?? Thanks in advance.
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10104
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9182
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7645
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.