Conditional Query selection on the basis of paarameters I have two sql:

1st:

Select emp.id from Employee
where '&amp;BI'=I
UNION ALL
Select emp.id from Employee
where '&amp;BI'&lt;&gt;I


2nd:same as first one but addition of few more tables and more union all

(
Select emp.id,sal.salary from Employee emp, Salary sal
where '&amp;BI'=I AND emp.id=100 AND '&amp;BI' Is not null
UNION ALL
Select emp.id,sal.salary from Employee emp, Salary sal
where '&amp;BI'&lt;&gt;I AND emp.id=100 AND '&amp;BI' Is not null
)
UNION ALL
(
Select emp.id,sal.salary from Employee emp, Salary sal
where '&amp;BI'=I AND emp.id=sal.id AND '&amp;BI' Is not null
UNION ALL
Select emp.id,sal.salary from Employee emp, Salary sal
where '&amp;BI'&lt;&gt;I AND emp.id=sal.id AND '&amp;BI' Is not null
)


want to combine both 1st and 2nd in to one select statement and run it dynamically.
Please help!!
I'm not sure you know what you are doing.

Two things about query #1: it is invalid, and it is useless. 

What is emp.? There's no table alias emp there ... It might be a function id that belongs to package named emp, but I somehow doubt it. You probably meant something like

select emp.id from employee emp
where ...


If that's so, it just doesn't make sense. The way you wrote it, it is equal to 

select id from employee


because the first SELECT returns values values "equal" to something, while the second one returns values "different" from that something, and you then UNION ALL them. That's the whole contents of the EMPLOYEE table.

The first part of query #2 is wrong as well; you're performing Cartesian product of employee and salary tables (and then restrict the result with WHERE clause). What is 

and '&amp;BI' is not null


condition used for? Did you mean

and I is not null


instead?

Also, what is I? The way you put it, it is a column in one of those tables (probably employee, according to query #1). No problem if that's so, it's just that it is somewhat unusual name for a column.

Now, what do you mean by "combining" those two queries? How? You can't UNION them because their column list doesn't match. What would you combine, then?

Finally, how do you run anything dynamically? What do you mean by saying that?

Please, provide a test case (create table &amp; insert into sample data), and - using that data - explain the result you'd want to get and rules that should make that happen.