Hi Sanjay
The code below will achieve what you want.
However, it will run VERY slowly, not because of the code, but because of the design of your queries. Perhaps you should redesign the queries to perform the checks more efficiently. But that is certainly beyong the scope of this question.
--
Graham