473,396 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 44564
me******@inter.net.il (mmm) wrote in message news:<95**************************@posting.google. 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.sysdummy1;
Nov 12 '05 #2
mmm
jb**********@aep.com (Jeff) wrote in message news:<15**************************@posting.google. com>...
me******@inter.net.il (mmm) wrote in message news:<95**************************@posting.google. 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.sysdummy1;

Hello,

I am using AS400/DB2 - should it (using the sysibm.sysdummy1) 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.sysdummy1 view is better for
performance?

Thanks a lot
Nov 12 '05 #3
mmm wrote:
jb**********@aep.com (Jeff) wrote in message news:<15**************************@posting.google. com>...
me******@inter.net.il (mmm) wrote in message news:<95**************************@posting.google. 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.sysdummy1;


Hello,

I am using AS400/DB2 - should it (using the sysibm.sysdummy1) 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.sysdummy1 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.SYSDUMMY1. 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
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...
6
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...
7
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...
3
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 =...
12
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...
5
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...
1
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...
22
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...
9
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...
13
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...

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.