2013-09-26 3 views
0

지난 한 해 동안이 쿼리를 매일 실행하려고합니다. 이 프로세스를 자동화하고 매일 MaxAgentsLoggedIn의 목록을 얻는 방법이 있습니까? 사전SQL Server 2008 저장 프로 시저 - 하루에 한 번 실행

select top 1 
    dIntervalStart IntervalStart, count(cName) MaxAgentsLoggedIn 
from IAgentQueueStats 
where cReportGroup = '*' 
    and cHKey3 = '*' 
    and cHKey4 = '*' 
    and tAgentLoggedIn > 0 
    and dIntervalStart >= '2013-09-24 00:00:00' 
    and dIntervalStart <= '2013-09-24 23:59:59' 
group by 
    nDuration, dIntervalStart 
order by 
    MaxAgentsLoggedIn desc; 

정의

 [cName] [nvarchar](50) NOT NULL, 
    [cReportGroup] [nvarchar](50) NOT NULL, 
[cHKey3] [nvarchar](50) NULL, 
[cHKey4] [nvarchar](50) NULL, 
[cType] [char](1) NOT NULL, 
[dIntervalStart] [datetime] NOT NULL, 
[nDuration] [int] NOT NULL, 
[nEnteredAcd] [int] NOT NULL, 
[nAbandonedAcd] [int] NOT NULL, 
[nGrabbedAcd] [int] NOT NULL, 
[nLocalDisconnectAcd] [int] NOT NULL, 
[nAlertedAcd] [int] NOT NULL, 
[nAnsweredAcd] [int] NOT NULL, 
[nAnswered] [int] NOT NULL, 
[nAcdSvcLvl] [int] NOT NULL, 
[nAnsweredAcdSvcLvl1] [int] NOT NULL, 
[nAnsweredAcdSvcLvl2] [int] NOT NULL, 
[nAnsweredAcdSvcLvl3] [int] NOT NULL, 
[nAnsweredAcdSvcLvl4] [int] NOT NULL, 
[nAnsweredAcdSvcLvl5] [int] NOT NULL, 
[nAnsweredAcdSvcLvl6] [int] NOT NULL, 
[nAbandonAcdSvcLvl1] [int] NOT NULL, 
[nAbandonAcdSvcLvl2] [int] NOT NULL, 
[nAbandonAcdSvcLvl3] [int] NOT NULL, 
[nAbandonAcdSvcLvl4] [int] NOT NULL, 
[nAbandonAcdSvcLvl5] [int] NOT NULL, 
[nAbandonAcdSvcLvl6] [int] NOT NULL, 
[tGrabbedAcd] [int] NOT NULL, 
[tAnsweredAcd] [int] NOT NULL, 
[mtAnsweredAcd] [int] NOT NULL, 
[tAbandonedAcd] [int] NOT NULL, 
[tTalkAcd] [int] NOT NULL, 
[tTalkCompleteAcd] [int] NOT NULL, 
[nHoldAcd] [int] NOT NULL, 
[tHoldAcd] [int] NOT NULL, 
[nAcw] [int] NOT NULL, 
[tAcw] [int] NOT NULL, 
[tAcwComplete] [int] NOT NULL, 
[nExternToInternCalls] [int] NOT NULL, 
[nExternToInternAcdCalls] [int] NOT NULL, 
[nInternToExternCalls] [int] NOT NULL, 
[nInternToExternAcdCalls] [int] NOT NULL, 
[nInternToInternCalls] [int] NOT NULL, 
[nInternToInternAcdCalls] [int] NOT NULL, 
[tExternToInternCalls] [int] NOT NULL, 
[tExternToInternAcdCalls] [int] NOT NULL, 
[tInternToExternCalls] [int] NOT NULL, 
[tInternToExternAcdCalls] [int] NOT NULL, 
[tInternToInternCalls] [int] NOT NULL, 
[tInternToInternAcdCalls] [int] NOT NULL, 
[nAcwCalls] [int] NOT NULL, 
[tAcwCalls] [int] NOT NULL, 
[nTransferedAcd] [int] NOT NULL, 
[nNotAnsweredAcd] [int] NOT NULL, 
[tAlertedAcd] [int] NOT NULL, 
[nFlowOutAcd] [int] NOT NULL, 
[tFlowOutAcd] [int] NOT NULL, 
[nStartWaitAlertAcdCalls] [int] NOT NULL, 
[nStartActiveAcdCalls] [int] NOT NULL, 
[nStartHeldAcdCalls] [int] NOT NULL, 
[nEndWaitAlertAcdCalls] [int] NOT NULL, 
[nEndActiveAcdCalls] [int] NOT NULL, 
[nEndHeldAcdCalls] [int] NOT NULL, 
[nTransferWithinAcdCalls] [int] NOT NULL, 
[nTransferOutAcdCalls] [int] NOT NULL, 
[nDisconnectAcd] [int] NOT NULL, 
[tAgentLoggedIn] [int] NOT NULL, 
[tAgentAvailable] [int] NOT NULL, 
[tAgentTalk] [int] NOT NULL, 
[tAgentOtherBusy] [int] NOT NULL, 
[tAgentOnAcdCall] [int] NOT NULL, 
[tAgentOnOtherAcdCall] [int] NOT NULL, 
[tAgentInAcw] [int] NOT NULL, 
[tAgentOnNonAcdCall] [int] NOT NULL, 
[tAgentDnd] [int] NOT NULL, 
[tAgentNotAvailable] [int] NOT NULL, 
[tAgentAcdLoggedIn] [int] NOT NULL, 
[tAgentStatusDnd] [int] NOT NULL, 
[tAgentStatusAcw] [int] NOT NULL, 
[tAgentLoggedInDiluted] [int] NOT NULL, 
[tStatusGroupFollowup] [int] NOT NULL, 
[tStatusGroupBreak] [int] NOT NULL, 
[tStatusGroupTraining] [int] NOT NULL, 
[CustomValue1] [int] NOT NULL, 
[CustomValue2] [int] NOT NULL, 
[CustomValue3] [int] NOT NULL, 
[CustomValue4] [int] NOT NULL, 
[CustomValue5] [int] NOT NULL, 
[CustomValue6] [int] NOT NULL, 
[I3TimeStampGMT] [datetime] NOT NULL, 
[SiteId] [smallint] NOT NULL, 
[SubSiteId] [smallint] NOT NULL, 
[nLocalDisconnectAgentAlertAcd] [int] NULL, 
[nLocalDisconnectAgentAcd] [int] NULL, 
[tAgentAcdLoggedIn2] [int] NULL 
+0

이 설명은 저장 프로 시저를 예약하는 방법을 보여줍니다. http://stackoverflow.com/questions/287060/scheduled-run-of-stored-procedure-on-sql-server – user2601995

+0

어떤 유형의 DB입니까? Oracle DB에서, 저장 프로 시저에 묶인 dbms_job을 사용하십시오. mySQL에서이 문서를보십시오. http://dev.mysql.com/doc/refman/5.1/en/events-overview.html –

답변

0

보다는 하루 쿼리를 반복에서

감사합니다, 당신은 하루에 의한 쿼리 일 다음 그룹을 포함 할 수있다?

Question 113045

는 쿼리에이 날짜를 추가 할 경우,

convert(date, dIntervalStart) 

를 사용하여 날짜 시간에서 불과 날짜를 당길 그런 다음 결과에서 최대 (AgentsLoggedIn)을 조회 할 수 있습니다 및 방법을 보여줍니다 답이있다 하루 목록을 얻으십시오.

select theDay, max(AgentsLoggedIn) MaxAgentsLoggedIn 
from (
    select convert(date, dIntervalStart) as theDay 
     dIntervalStart IntervalStart, count(cName) AgentsLoggedIn 
    from IAgentQueueStats 
    where cReportGroup = '*' 
     and cHKey3 = '*' 
     and cHKey4 = '*' 
     and tAgentLoggedIn > 0 
     and dIntervalStart >= '2013-09-24 00:00:00' 
     and dIntervalStart <= '2013-09-24 23:59:59' 
    group by 
     nDuration, dIntervalStart) as q 
group by theDay; 
+0

안녕하세요. tAgentloggedin입니다. 에이전트가 로그인 한 시간은 타임 스탬프가 아닙니다. 큐리는 하루 동안 올바르게 작동합니다. 나는 여러 날을 달리기 위해 노력하고 있습니다. – user2817598

+0

질문을 편집하여 테이블 정의를 추가 할 수 있습니까? - 적어도 관련 칼럼의 정의? 그게 도움이 될거야. – GregA100k

+0

안녕 G_A. 테이블 정의를 추가했습니다. – user2817598

관련 문제