SQL Server - problemas con los selects

   
Vista:

problemas con los selects

Publicado por Alexandra Narvaez (1 intervención) el 19/06/2009 20:10:11
Buenas tardes,
necesito ayuda de urgen

tengo un store procedure donde debo imprimir un reporte general de las campañas y tipos de llamadas.

ALTER PROCEDURE [dbo].[pr_Report_TotCalls]
(
@dateB as datetime,
@dateE as datetime

)
AS
declare
@answer AS INT,
@nanswer AS INT,
@busy AS INT,
@aban as int,
@wait as int,
@tot as int
set @busy=0; set @answer =0;
set @nanswer =0;set @busy =0; set @aban =0;
Select @answer=count(s.Sta_Code) FROM dbo.tb_Statistic s inner join tb_Campain c on s.Cam_Code = c.Cam_Code where s.Sta_Status ='C' group by c.Cam_Code, c.Cam_Description, c.Cam_BeginDate, c.Cam_EndDate order by c.Cam_Code asc;
Select @busy=count(s.Sta_Code) FROM dbo.tb_Statistic s inner join tb_Campain c on s.Cam_Code = c.Cam_Code where s.Sta_Status ='B' group by c.Cam_Code, c.Cam_Description, c.Cam_BeginDate, c.Cam_EndDate order by c.Cam_Code asc;
Select @nanswer=count(s.Sta_Code) FROM dbo.tb_Statistic s inner join tb_Campain c on s.Cam_Code = c.Cam_Code where s.Sta_Status ='N' group by c.Cam_Code, c.Cam_Description, c.Cam_BeginDate, c.Cam_EndDate order by c.Cam_Code asc;
Select @aban=count(Sta_Code) from ((dbo.tb_Statistic s join tb_Campain c on s.Cam_Code=c.Cam_Code)join tb_Service e on c.Srv_Code=e.Srv_Code) where Sta_Status <>'C' and LTRIM(RTRIM(datediff(ss,Sta_DateTimeBegin,Sta_DateTimeEnd)))<(Srv_LeaveCall) group by s.Cam_Code, c.Cam_Description, c.Cam_BeginDate, c.Cam_EndDate order by s.Cam_Code asc;
Select @tot=count(Sta_Code) FROM dbo.tb_Statistic group by Cam_Code order by Cam_Code asc;

SELECT distinct c.Cam_Code, c.Cam_Description, c.Cam_BeginDate, c.Cam_EndDate, @tot,@answer,@nanswer, @busy,s.Srv_WaitMinContact
FROM ((tb_Campain c INNER JOIN tb_Service s ON c.Srv_Code=s.Srv_Code) inner join tb_Statistic t on c.Cam_Code=t.Cam_Code)
where (t.Sta_DateTimeBegin>=@dateB and t.Sta_DateTimeEnd<=@dateE)
GROUP BY c.Cam_Code,c.Cam_Description, c.Cam_BeginDate, c.Cam_EndDate, s.Srv_WaitMinContact
order by c.Cam_Code asc

el problemas es que cuando realiza la busqueda de las variables @answer, ,@nanswer, @busy me sale el primer dato de cada una... no se agrupa ayudenme ya probe de todo y no se q me recomiendan
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
Imágen de perfil de Isaias

RE:problemas con los selects

Publicado por Isaias (3186 intervenciones) el 20/06/2009 00:01:34
Veamos, tomando tu primer linea, como es que haces un SUM

count(s.Sta_Code)

y quieres agrupar por:

group by c.Cam_Code, c.Cam_Description, c.Cam_BeginDate, c.Cam_EndDate

Y no solo eso, ademas le agregas un ORDER BY:

order by c.Cam_Code asc
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