I am using CTE for union two columns in sql.
If I am executing these two queries it is working fine .
But I want to make union of these two for more simpler O/P.

I am getting compile time error :

Incorrect syntax near the keyword 'DECLARE'.

can anyone tell me hoe to achieve union with cte

```
DECLARE @Inward DATETIME
SET @Inward = DATEADD(mm, -6, CURRENT_TIMESTAMP);
WITH cte AS 
(
SELECT 0 AS TheMonth 
UNION ALL 
SELECT TheMonth + 1 
FROM cte
WHERE TheMonth < 5
) 
SELECT  
cte.TheMonth,
isnull(sum(qty),0) as inward 
FROM 
cte 
LEFT OUTER JOIN RS_GIN_Master as g 
ON accept_date >= DATEADD(MM, cte.TheMonth, @Inward) AND accept_date < DATEADD(MM, cte.TheMonth + 1, @Inward)

UNION all 

DECLARE @Outward DATETIME
SET @Outward = DATEADD(mm, -6, CURRENT_TIMESTAMP);
WITH cte AS
(
SELECT 0 AS TheMonthO 
UNION ALL
SELECT TheMonthO + 1 
FROM cte 
 WHERE TheMonthO < 5
) 

SELECT  isnull(sum(quantity),0) as outward 
FROM 
cte 
LEFT OUTER JOIN 
RS_Sell_Order_Master as s 
ON del_date >= DATEADD(MM, cte.TheMonthO, @Outward) AND del_date < DATEADD(MM, cte.TheMonthO + 1, @Outward) and isDelivered = 1
left outer join RS_Sell_Order_Mapping as sm on sm.sell_order_no = s.sell_order_no     

```