2013-08-28 204 views
0

我使用SQL Server 2000,從而無法使用CTE的連接三個SQL查詢

DECLARE @reportdate AS DATETIME 

SET @reportdate='08/26/2013' 

1查詢

SELECT SUM(NENTEREDACD) AS calls, 
     DINTERVALSTART 
FROM dbo.QUEUESTATS 
WHERE (DINTERVALSTART > @reportdate + ' 00:00:00.000') 
     AND (DINTERVALSTART < DATEADD(d, 1, @reportdate) + ' 00:00:00.000') 
GROUP BY DINTERVALSTART 
ORDER BY DINTERVALSTART 

第二查詢

SELECT count(cname) AS AvaiAgents, 
     dintervalstart AS startdatetime 
FROM (SELECT dintervalstart, 
       cname 
     FROM [dbo].[AGENTSTATS] 
     GROUP BY dintervalstart, 
        cname 
     HAVING (DINTERVALSTART > @reportdate + ' 00:00:00.000') 
       AND (DINTERVALSTART < DATEADD(d, 1, @reportdate) + ' 00:00:00.000')) T 
GROUP BY T.dintervalstart 

3ND查詢

SELECT count(cname) AS ActiveAgents, 
     dintervalstart AS startdatetime 
FROM (SELECT dintervalstart, 
       cname 
     FROM [dbo].[AGENTSTATS1] 
     GROUP BY dintervalstart, 
        cname 
     HAVING (DINTERVALSTART > @reportdate + ' 00:00:00.000') 
       AND (DINTERVALSTART < DATEADD(d, 1, @reportdate) + ' 00:00:00.000')) T 
GROUP BY T.dintervalstart 

我想只拉第一個查詢的記錄,所以它應該像 ,所以我需要從三個不同的查詢獲得三列。常見的是時間戳

I inetval  Calls Avaiagents  Active agents 
08/26/2012 20  22    23 
+0

查找到UNION ALL它可以讓你對所有三個查詢加入到一個表 –

回答

0

cte's只是使用using關鍵字派生表。你能以老式的方式做到嗎?

select somefields 
from a_table join 
(select etc) temp on t.something = a_table.something 
+0

第一也是一個查詢 – nangel

+0

這是否有什麼區別? –