Solved

DB2 sql: where clausole : something OR (table is empty)

Posted on 2011-03-08
5
508 Views
Last Modified: 2012-05-11
HI,
I would like to have
a condition where in which I test if an element is present
in a tableX OR the tableX is empty.
The where will return true if the element is present in tableX
BUT return true even if the tableX is empty.
How do I do?
thanks
0
Comment
Question by:bobdylan75
  • 3
5 Comments
 

Author Comment

by:bobdylan75
ID: 35069487
select * from tableA
where tableA.key in (select key from tableX) OR tableX is empty...

Is there a way like that..
0
 
LVL 45

Accepted Solution

by:
Kent Olsen earned 500 total points
ID: 35069551

Hi Bob,

SELECT * FROM tableA
WHERE tableA.key in (select key from tableX)
  OR ((Select count(*) from tablex) = 0)


Will that work?


Kent
0
 
LVL 3

Expert Comment

by:CarlsbergFTW
ID: 35069646
Try using an outer join against the table that might have null or no value ?
0
 

Author Comment

by:bobdylan75
ID: 35070181
Thank you CarlsbergFTW,
but I think the easy way is that one of Kdo.
0
 

Author Closing Comment

by:bobdylan75
ID: 35070184
thank you!
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Domino Lotusscript Scheduled Agent Tranfer File from AS400 to another 6 119
Read spool files from iseries in C# 4 284
AS400 CPU allocation 3 111
RUNRMTCMD from AS/400 12 68
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 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