2013-09-26 77 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

什麼類型的數據庫?在Oracle數據庫中,使用綁定到存儲過程的dbms_job,在mySQL中,查看此文檔:http://dev.mysql.com/doc/refman/5.1/en/events-overview.html –

回答

0

而不是通過迭代天查詢,可以在查詢中包含的一天,然後按這一天嗎?

Question 113045有一個答案,顯示瞭如何使用

convert(date, dIntervalStart) 

拉剛剛從日期時間的日期如果添加此日期查詢,那麼你可以從結果查詢MAX(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

相關問題