SQL - Reporte T-SQL

 
Vista:

Reporte T-SQL

Publicado por Jose Castillo (3 intervenciones) el 06/12/2006 04:04:57
Saludos, tengo un pequeño problema con un reporte, necesito crear un reporte de concurrencia de visitas a medicos.... o sea la logica se concentra en que tengo un visitador medico que visita la oficina de un medico en 12 ciclos diferentes...todos los datos estan en tablas diferentes(medicos,ciclos,tareasrealizadas(visitas)) y para esto tengo un inner join para relacionarlas, ahora necesito contabilizar las visitas que hizo cada visitador en cada ciclo y hasta ahora tengo esto

select tr.medicid,medic.name,medic.lastname,specialty.description,
medic.city,cycle.cycleno,
(select count(*) from tarearealizada where route between '1' and '9' and medicid between '2262' and '4475' and cycleno='1' and tareaid='16') as C1,
(select count(*) from tarearealizada where route between '1' and '1' and medicid between '2262' and '2262' and cycleno='2' and tareaid='16') as C2,
(select count(*) from tarearealizada where route between '1' and '1' and medicid between '2262' and '2262' and cycleno='3' and tareaid='16') as C3,
(select count(*) from tarearealizada where route between '1' and '1' and medicid between '2262' and '2262' and cycleno='4' and tareaid='16') as C4,
(select count(*) from tarearealizada where route between '1' and '1' and medicid between '2262' and '2262' and cycleno='5' and tareaid='16') as C5,
(select count(*) from tarearealizada where route between '1' and '1' and medicid between '2262' and '2262' and cycleno='6' and tareaid='16') as C6,
(select count(*) from tarearealizada where route between '1' and '9' and medicid between '2262' and '4475' and cycleno='7' and tareaid='16' group by route,medicid) as C7,
(select count(*) from tarearealizada where route between '1' and '1' and medicid between '2262' and '2262' and cycleno='8' and tareaid='16') as C8,
(select count(*) from tarearealizada where route between '1' and '1' and medicid between '2262' and '2262' and cycleno='9' and tareaid='16') as C9,
(select count(*) from tarearealizada where route between '1' and '1' and medicid between '2262' and '2262' and cycleno='10' and tareaid='16' ) as C10,
(select count(*) from tarearealizada where route between '1' and '1' and medicid between '2262' and '2262' and cycleno='11' and tareaid='16') as C11,
(select count(*) from tarearealizada where route between '1' and '1' and medicid between '2262' and '2262' and cycleno='12' and tareaid='16') as C12
FROM tarearealizada tr
INNER JOIN medic on tr.medicid=medic.medicid
INNER JOIN specialty on medic.specialtyid=specialty.specialtyid
INNER JOIN cycle on tr.cycleid=cycle.cycleid
where tr.tareaid='16'
GROUP BY tr.medicid,medic.name,medic.lastname,specialty.description,
medic.city,cycle.cycleno

en el subquery donde agrupe me dan un error
Subquery returned more than 1 value
perdonen si no me explique bien.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Reporte T-SQL

Publicado por Isaías (5072 intervenciones) el 06/12/2006 18:58:11
Pues no alcanzo a ver dicho SUB-QUERY
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

RE:Reporte T-SQL

Publicado por Liliana (426 intervenciones) el 07/12/2006 16:58:23
Hola,
Donde calculas C7, "group by route,medicid", te devolverá más de un valor.
Liliana.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Reporte T-SQL

Publicado por Isaías (5072 intervenciones) el 07/12/2006 18:43:30
Vista de LINCE !!!, solo eso.

Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar