I think You want
SELECT a,b,c
FROM my_table
WHERE (in_emp_id = 0 OR exh_emp_id = in_emp_id)
AND (in_date_from = 0 OR xh_valid_from = in_date_from);
Main Topics
Browse All TopicsCan i write the following query:
SELECT a,b,c FROM my_table
WHERE CASE in_emp_id = 0 AND date_from <> 0 THEN exh_valid_from = in_date_from
, CASE in_emp_id <> 0 AND in_date_from <> 0 THEN exh_emp_id = in_emp_id
, CASE in_emp_id <> 0 AND in_date_from <> 0 THEN exh_valid_from = in_date_from AND exh_emp_id = in_emp_id;
in_date_from and in_emp_id are input parameters passed to the procedure which contains this query.
exh_emp_id and exh_valid_from are dates from my_table.
Can someone help me out
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Your 2nd & 3rd CASE conditions do not make sense since they evaluate the same conditions, but return diff. results : -
, CASE in_emp_id <> 0 AND in_date_from <> 0 THEN exh_emp_id = in_emp_id
, CASE in_emp_id <> 0 AND in_date_from <> 0 THEN exh_valid_from = in_date_from AND exh_emp_id = in_emp_id;
I suppose they shud be as below : -
CASE in_emp_id = 0 AND in_date_from <> 0 THEN exh_valid_from = in_date_from
, CASE in_emp_id <> 0 AND in_date_from = 0 THEN exh_emp_id = in_emp_id
, CASE in_emp_id <> 0 AND in_date_from <> 0 THEN exh_valid_from = in_date_from AND exh_emp_id = in_emp_id;
If i understand ur requirement correctly, u have a procedure that has 2 IN parameters - in_emp_id, in_from_date
that u want to compare to ur table values.
Wat u need is as below : -
SELECT a, b, c FROM my_table
WHERE DECODE(in_emp_id, 0, exh_emp_id, in_emp_id) = exh_emp_id
AND DECODE(in_date_from, 0, exh_valid_from, in_date_from) = exh_valid_from
Business Accounts
Answer for Membership
by: actonwangPosted on 2006-10-22 at 19:19:59ID: 17786188
I think that what you want is like :
SELECT a,b,c FROM my_table
WHERE (in_emp_id = 0 AND date_from <> 0 and exh_valid_from = in_date_from ) or
(in_emp_id <> 0 AND in_date_from <> 0 and exh_emp_id = in_emp_id) or
(CASE in_emp_id <> 0 AND in_date_from <> 0 and exh_valid_from = in_date_from AND exh_emp_id = in_emp_id)
/
right :)
Acton