UNION With If?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way of generating a CONDITIONAL UNION for instance

SELECT PRO_ID, PRO_NAME, PRO_VALUE FROM PRODUCT WHERE PRO_NAME="RULER"

IF (SELECT COUNT(PRO_ID) FROM ANOTHER_PRODUCT WHERE PRO_VALUE=10)=1 THEN

UNION A

ELSE

UNION B

Is it possible?
 
Is there a way of generating a CONDITIONAL UNION for instance

SELECT PRO_ID, PRO_NAME, PRO_VALUE FROM PRODUCT WHERE PRO_NAME="RULER"

IF (SELECT COUNT(PRO_ID) FROM ANOTHER_PRODUCT WHERE PRO_VALUE=10)=1 THEN

UNION A

ELSE

UNION B

Is it possible?

Not really. You would need to build the SQL in code.

What you can do, though, is union both A and B using criteria so that
the query doesn't return any records for the undesired table.

Do you really have a different table for each product? If so, you may
want to reconsider your table design - storing data (Another_Product
e.g.) in tablenames is most unwise!

John W. Vinson[MVP]
 
Dear Carlos:

If you can express the condition inside the WHERE clause of a query, then
you can put that into the SQL for A, and negatively for B. That should do
it.

To help you do that, I'd need to have a lot more information. Perhaps
sample data, plus the full details of SELECT queries for A and B.

Tom Ellison
 
Back
Top