Well, I want to use WITH before the query but I miss an error, I attach the query of how I put the WITH and the error.
DECLARE @cod_centro VARCHAR(2)
DECLARE @fec_annomes int
SET @cod_centro='MC'
SET @fec_annomes='201810'
WITH TH_Hospitalizacion AS
(
select @cod_centro, @fec_annomes, 225,count(* ),getdate()
from TH_Hospitalizacion t
where t.cod_centro = @cod_centro and year(t.fec_alta)*100+month(t.fec_alta) = @fec_annomes
and xti_excluido ='n' and xti_tipoProceso='H'
AND EXISTS (SELECT COD_EPISODIO FROM TH_TomaFormulario A WITH (NOLOCK)
INNER JOIN TH_ValorIndicadorTomaFormulario_2 B WITH (NOLOCK) ON A.cod_TomaFormulario = B.cod_TomaFormulario
AND B.COD_INDICADOR IN ('5913',
'10965',
'48128')
and des_ValorIndicador IN ('0','1','2','3','4','5','6','7','8','9', '10')
AND t.cod_Episodio=A.cod_Episodio
AND A.cod_centro=@cod_centro)
)
This is the error message.
Sintaxis incorrecta junto a la palabra clave 'with'. Si esta instrucción es una expresión de tabla común, una cláusula xmlnamespaces o una cláusula de contexto de seguimiento de cambios, la instrucción anterior debe terminarse con punto y coma.
If someone knows how to solve it, I would appreciate it a lot.
Greetings and thanks in advance.