PDE Problem - (really just an integral)

This problem isn't too bad in theory. I understand it, I'm just having great difficulty expressing the answer, so I'm wondering if anyone has some method, or insight how to "see" or express the answer.

Question:

{

Find from the formula:

If in the solid sphere and outside. ...

}

The "..." just represents the other part of the question that I'm not interested in.

As an example if we set:

The integral would drop to:

This makes sense, that as long as we integrate below R we get our integral back. But when we get above R then the integral returns 0. My question is this I guess...

Is there an easy way to setup all these equalities and integrals? Because I am getting lost when I try to do it. The only time it really makes sense is when I plug in numbers and force my way through it. I'm just curious what a better way to accomplish this task of setting up cases is. Thanks in advance.