在上一个问题中,你们帮助我从不同的行中获取数据。我使用的语句在 MS SQL Server Management Studio 上运行良好。我可以在没有任何错误的情况下运行该语句并返回我需要的数据。但是,我需要在我们的前端程序上运行这些数据。当我尝试在这个程序上运行我的语句时,它只是挂起。我有一种感觉,该语句的“With As”部分正在引起问题。有没有办法通过把这个临时表放在子查询中来重写这个语句?
WITH Temp1 AS (SELECT
SkillTargetID = Agent_Logout.SkillTargetID,
LogoutDateTime = Agent_Logout.LogoutDateTime,
LogonDate = DateAdd(s,-1 * Agent_Logout.LoginDuration,Agent_Logout.LogoutDateTime),
ROW_NUMBER() OVER(PARTITION BY Agent_Logout.SkillTargetID ORDER BY Agent_Logout.LogoutDateTime ASC) RowVersion,
LoginDuration = Agent_Logout.LoginDuration
FROM Agent_Logout)
SELECT
AgentID = Base.SkillTargetID,
LogonDate = Base.LogonDate,
BaseLogout = Base.LogoutDateTime,
BaseDuration = Base.LoginDuration,
NextLogon = Temp1.LogonDate,
LogoutDuration = DateDiff(s,Base.LogoutDateTime,Temp1.LogonDate)
FROM Temp1 Base
LEFT JOIN Temp1 ON Base.SkillTargetID = Temp1.SkillTargetID
AND Base.RowVersion = Temp1.RowVersion-1