Subject Re: [ib-support] create procedure
Author Svein Erling Tysvær
Rotandiko, let's do some cleaning up (or rather, start from scratch
rewriting your SQL without an SP - incorporate it into an SP if you want to):

SELECT DISTINCT OBJECT_TYPE_ID FROM M_OBJECT_TYPE M1
WHERE M1.OBJECT_TYPE_ID = :ObjectTypeId OR
EXISTS(SELECT 1 FROM M_OBJECT_TYPE M2
WHERE M2.PARENT_OBJECT_TYPE_ID = M1.OBJECT_TYPE_ID
AND M2.OBJECT_TYPE_ID = :ObjectTypeId) OR
EXISTS(SELECT 1 FROM M_OBJECT_TYPE M2
JOIN M_OBJECT_TYPE M3
ON M3.OBJECT_TYPE_ID = M2.PARENT_OBJECT_TYPE_ID
WHERE M2.PARENT_OBJECT_TYPE_ID = M1.OBJECT_TYPE_ID
AND M3.OBJECT_TYPE_ID = :ObjectTypeId)

I think this should be what you're looking for, and probably execute faster
than your SP (I don't like comparisons using IN <sub-select>).

HTH,
Set