Now, If the "deptid" is null for id =1, I want to retrieve the "amt" from dept table, else I want to get the sum of "amt"
from "dept2" table for id = 1 and parentid is null.
(note: There will be only one "null" deptid for a particular id)
ie, I want a qry which returns,
id amt
---- -----
1 500 --rec3
when there is a deptid with null in the dept table for id = 1.
or:
id amt
---- -----
1 600 --prec1 + prec2 + prec5
Pseudocode:
--------------
if there is a null deptid, for the given "id", I want to diplay the "id", "amt" from "dept"
else
display the "id", sum(dept) from dept2 where parentdep is null for the given "id"
(
SELECT id, amt FROM dept WHERE id=1 AND deptid IS NULL
)
UNION ALL
(
SELECT id, SUM() amt FROM dept2 GROUP BY id
WHERE id=1 AND parentdep IS NULL
AND NOT EXISTS (SELECT id, amt FROM dept WHERE id=1 AND deptid IS NULL)
);
HTH,
Jurij Modic ASCII a stupid question, get a stupid ANSI
24 hours in a day .... 24 beer in a case .... coincidence?
Bookmarks