I have the following query:
;WITH TABLA1 AS (
SELECT COUNT(*) AS TOTAL_EMPLEADOS,
TERRITORIO
FROM AR_EMPLEADOS
WHERE ANIO = 2018
AND TERRITORIO = 'A'
GROUP BY TERRITORIO
)
;WITH TABLA2 AS (
SELECT COUNT(*) AS TOTAL_PRODUCTOS,
TERRITORIO
FROM AR_PRODUCTOS
WHERE ANIO = 2018
AND TERRITORIO = 'A'
GROUP BY TERRITORIO
)
SELECT A.TERRITORIO,
A.TOTAL_EMPLEADOS,
B.AR_PRODUCTOS
FROM TABLA1 A
INNER JOIN TABLA2 B ON A.TERRITORIO = B.TERRITORIO
Mistake:
Incorrect syntax near ';'.
What am I trying to do if possible with the statement WITH
?
To use multiple" common table expression the proper syntax is:
For example:
And in your case:
the correct syntax would be
PS: the semicolon
;
is to execute several statements, if you don't have any statement before the first WITH it seems to me that it won't work for you. In other words[SQL Statement] ;
[SQL Statement] ;
[SQL Statement] ;
[SQL Statement] ;
[SQL Statement] ;
[SQL Statement] ;