The Biot-Savart law for the magnetic field at a point, r , in space due to a constant-current carrying conductor is given as :
$$\boldsymbol{B}(\boldsymbol{r}) = \frac{\mu_0}{4\pi}I\int_c \frac{d\boldsymbol{l}\times\hat{r'}}{r'^2}$$
($\boldsymbol{r'}$ is the vector from the position of $d\boldsymbol{l}$ to the point you are interested in ($\boldsymbol{r}$) ). The contour over which the integration takes place, is just the path the current is going i.e. along the conductor.
I want to use this definition to find the magnetic field produced by a circular wire at a point, p, along the central axis of the conductor which is at a distance, a, from the centre, using the component form of the vectors. I have been able to calculate $\boldsymbol{B}$ already using an alternative approach but when redoing the calculation in component form I run into trouble. I have two pictures below that will help :

In Cartesian coordinates, $d\boldsymbol{l} = \hat{x}dx + \hat{y}dy + \hat{z}dz$, and for integrating around the circular wire:
$$R^2 = x^2 + y^2 \rightarrow dy = - \frac{xdx}{\sqrt{R^2 - x^2}}$$
This gives
$$d\boldsymbol{l} = dx[-\hat{x} + \frac{x}{\sqrt{R^2 -x^2}}\hat{y} ]$$
For $0\le \phi \le \pi$
For $\pi \le \phi \le 2\pi$, I get
$$d\boldsymbol{l} = [\hat{x} + \frac{x}{\sqrt{R^2 -x^2}}\hat{y}]dx$$
Looking at the images, it can be seen that
$$\hat{r'} = \frac{1}{r'}[-R\cos{\phi}\hat{x} -R\sin{\phi}\hat{y} +a\hat{z}]$$
Plugging in results to Biot-Savart law and integrating from R to -R (counter-clockwise) and then from -R to R using dl for positive and negative y quadrants give me the incorrect results.
Do I have to be careful with the sine and cosine terms when integrating over the four quadrants, can I just replace the cosine and sine terms with $\frac{x}{R}$ and $\frac{\sqrt{R^2 - x^2}}{R}$?
Is the setup above correct (are my vectors correct)?
Is there Anything that needs to be done carefully?
First I'm going to do the calculation in polar coordinates, because it is far easier to not make a mistake in this context. This will help reassure us that my calculation in Cartesian coordinates is valid.
$$d\vec{l} = R d\theta \Big( -\sin(\theta)\hat{x} + \cos(\theta)\hat{y} \Big)$$
$$ \hat{r}' = - \frac{R}{\sqrt{R^2+a^2}} \cos(\theta)\hat{x} - \frac{R}{\sqrt{R^2+a^2}} \sin(\theta) \hat{y} + \frac{a}{\sqrt{R^2+a^2}} \hat{z} $$
$$ d\vec{l}\times \hat{r}' = \left| \begin{array}{ccc} \ \hat{x} & \hat{y} & \hat{z} \\ -d\theta \ R\sin(\theta) & d\theta \ R\cos(\theta) & 0 \\ - \frac{R}{\sqrt{R^2+a^2}} \cos(\theta) & - \frac{R}{\sqrt{R^2+a^2}} \sin(\theta) & \frac{a}{\sqrt{R^2+a^2}} \end{array} \right|$$
$$ = \frac{1}{\sqrt{R^2+a^2}} d\theta \Big( Ra \cos(\theta)\hat{x} + Ra\sin(\theta) \hat{y} + R^2 \hat{z} \Big)$$
The magnetic field is then,
$$ \vec{B} = \frac{\mu_0 I }{4\pi} \int_{0}^{2\pi} \frac{ d\theta}{(R^2+a^2)^{3/2}} \Big( Ra \cos(\theta)\hat{x} + Ra\sin(\theta) \hat{y} + R^2 \hat{z} \Big)$$
$$ = \frac{\mu_0 I }{4\pi} \int_{0}^{2\pi} \frac{d\theta}{(R^2+a^2)^{3/2}} \Big( 0+0 + R^2 \hat{z} \Big)$$
$$ = \frac{\mu_0 I }{4\pi} \frac{2\pi}{(R^2+a^2)^{3/2}} \Big( R^2 \hat{z} \Big)$$
$$ = \frac{\mu_0 I }{2} \frac{R^2 }{(R^2+a^2)^{3/2}} \ \hat{z} $$
As you said the equation of the circle is $x^2+y^2=R^2$ which allows us to compute $d\vec{l}$ using derivatives.
$$d\vec{l} = dx \ \hat{x} + dy \ \hat{y} + 0 \ \hat{z} = dx \ \hat{x} + y'(x) dx \ \hat{y} + 0 \ \hat{z} = dx \ \hat{x} \mp \frac{x dx}{\sqrt{R^2-x^2}} \hat{y} + 0 \ \hat{z}$$
$$\boxed{ d\vec{l} = dx \ \Big( \hat{x} \mp \frac{x }{\sqrt{R^2-x^2}} \hat{y} + 0 \ \hat{z} \Big)}$$
Where the $-$ corresponds to $y>0$ and the $+$ corresponds to $y<0$.
Let the element of current be located at $(x,y(x),0)$ then the unit vector which points from \hat{r}' is given by,
$$ \boxed{\hat{r}' = \frac{-x \ \hat{x} \mp \sqrt{R^2-x^2} \ \hat{y} + a\hat{z}}{\sqrt{R^2+a^2}}} $$
where the $-$ corresponds to $y>0$ and the $+$ corresponds to $y<0$.
$$ d\vec{l} \times \hat{r}' = \left| \begin{array}{ccc} \ \hat{x} & \hat{y} & \hat{z} \\ dx & \mp \frac{x dx}{\sqrt{R^2-x^2}} & 0 \\ \frac{-x}{\sqrt{R^2+a^2}} & \mp \frac{\sqrt{R^2-x^2}}{\sqrt{R^2+a^2}} & \frac{a}{\sqrt{R^2+a^2}}\end{array} \right|$$
$$ = \hat{x}\Big(\mp \frac{x dx}{\sqrt{R^2-x^2}}\frac{a}{\sqrt{R^2+a^2}} - 0 \Big) - \hat{y}\Big( dx \ \frac{a}{\sqrt{R^2+a^2}} - 0 \Big) + \hat{z}\Big( \mp dx \frac{\sqrt{R^2-x^2}}{\sqrt{R^2+a^2}} \pm \frac{x dx}{\sqrt{R^2-x^2}} \frac{-x}{\sqrt{R^2+a^2}}\Big)$$
$$ \boxed{ d\vec{l} \times \hat{r}'= \mp \hat{x} \frac{xa dx}{\sqrt{R^2-x^2}\sqrt{R^2+a^2}} - \hat{y} \ \frac{a\ dx}{\sqrt{R^2+a^2}} \mp\hat{z} \ dx \frac{R^2}{\sqrt{R^2-x^2}\sqrt{R^2+a^2}} }$$
There will be two contributions to the magnetic field. One from the top semicircle and one from the bottom semicircle.
$$ \vec{B}_{top} = \frac{\mu_0 I}{4\pi} \frac{1}{R^2+a^2}\int_{R}^{-R} \Big(- \hat{x} \frac{xa dx}{\sqrt{R^2-x^2}\sqrt{R^2+a^2}} - \hat{y} \ \frac{a\ dx}{\sqrt{R^2+a^2}} -\hat{z} \ dx \frac{R^2}{\sqrt{R^2-x^2}\sqrt{R^2+a^2}} \Big) $$
$$= \frac{\mu_0 I}{4\pi} \frac{1}{R^2+a^2} \Big(0 - \hat{y} \ \frac{a\ (-2R)}{\sqrt{R^2+a^2}} - \hat{z} \ \frac{-\pi R^2}{\sqrt{R^2+a^2}}\Big) $$
$$= \frac{\mu_0 I}{4\pi} \frac{1}{R^2+a^2} \Big( \hat{y} \ \frac{2aR}{\sqrt{R^2+a^2}} +\hat{z} \ \frac{\pi R^2}{\sqrt{R^2+a^2}}\Big) $$
$$ \vec{B}_{bottom} = \frac{\mu_0 I}{4\pi} \frac{1}{R^2+a^2}\int_{R}^{-R} \Big( \hat{x} \frac{xa dx}{\sqrt{R^2-x^2}\sqrt{R^2+a^2}} - \hat{y} \ \frac{a\ dx}{\sqrt{R^2+a^2}} \hat{z} \ dx \frac{R^2}{\sqrt{R^2-x^2}\sqrt{R^2+a^2}} \Big) $$
$$ \vec{B}_{bottom} = \frac{\mu_0 I}{4\pi} \frac{1}{R^2+a^2} \Big(0 - \hat{y} \ \frac{2aR}{\sqrt{R^2+a^2}} +\hat{z} \ \frac{\pi R^2}{\sqrt{R^2+a^2}} \Big) $$
$$ \vec{B}_{bottom} = \frac{\mu_0 I}{4\pi} \frac{1}{R^2+a^2} \Big( \hat{y} \ \frac{-2aR}{\sqrt{R^2+a^2}} +\hat{z} \ \frac{\pi R^2}{\sqrt{R^2+a^2}} \Big) $$
And the complete magnetic field is,
$$\vec{B} = \vec{B}_{top}+\vec{B}_{bottom} $$
$$\vec{B} = \frac{\mu_0 I}{4\pi} \frac{1}{R^2+a^2} \Big( \ \frac{2\pi R^2}{\sqrt{R^2+a^2}} \Big)\ \hat{z} $$
$$\vec{B} = \frac{\mu_0 I}{2} \frac{R^2}{(R^2+a^2)^{3/2}} \ \hat{z} $$