I have a query where I use 1 subquery to get data from several tables. And as a result, it returns a total of 2947 records.
--CONSULTA INICIAL
SELECT dniEgre,
(SELECT TOP 1 CASE WHEN numeRespu = 1 THEN 'SI' ELSE 'NO' END
FROM OCL.tblDetalleRespuNumero
WHERE idPregun = '201' AND dniUsu = dniEgre collate Modern_Spanish_CI_AI
ORDER BY dniEgre DESC) as Trabaja
FROM OCL.tblEgresado
WHERE dniEgre IN
(SELECT dniUsu collate Modern_Spanish_CI_AI FROM OCL.tblExperiencia);
Now I want to use the count
function to count the (SI)
and the (NO)
from my previous query.
---consulta para hallar cuantos si trabajan
SELECT count ((SELECT numerespu
FROM OCL.tblDetalleRespuNumero
WHERE idPregun = '201' AND numeRespu=1 AND dniUsu = dniEgre collate Modern_Spanish_CI_AI) as SiTrabaja)
FROM OCL.tblEgresado
WHERE dniEgre IN
(SELECT dniUsu collate Modern_Spanish_CI_AI FROM OCL.tblExperiencia);
---consulta para hallar cuantos NO trabajan
SELECT count( (SELECT numerespu
FROM OCL.tblDetalleRespuNumero
WHERE idPregun = '201' AND numeRespu=0 AND dniUsu = dniEgre collate Modern_Spanish_CI_AI) as NoTrabaja)
FROM OCL.tblEgresado
WHERE dniEgre IN
(SELECT dniUsu collate Modern_Spanish_CI_AI FROM OCL.tblExperiencia);
But when using count
in the subqueries I get this error:
'count' is not a recognized built-in function name.
I hope you can help me with this error, to be able to count the records.