Hi Janice,
Unfortunately I don't have enough time to delve into this... And I don't even know what you're trying to achieve. Basically it is still your code since I only removed 'BEGIN' keywords after 'THEN' and added couple of 'IF's after 'END's to make it compliant with SQL script syntax.
I'd say that you need to check where subqueries are located in this code and check if they are not too generic. You can simply use TOP 1.
Kind regards,
Radek