Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Results for Multiple Dates

Author  Topic 

ladiaocb
Yak Posting Veteran

57 Posts

Posted - 2004-06-24 : 14:15:02
Hello,

Having some trouble with a query. I am trying to write a query that returns scores for each user for 3 different months. Here is what I have so far:

select q.[description] as Queue, a.firstName + ' ' + a.lastname as Agent,
March=(select s.score where s.period='03/01/2004'),
April=(select s.score where s.period='04/01/2004'),
May=(select s.score where s.period='05/01/2004')
from agent a LEFT OUTER JOIN service_level_report s
ON a.id = s.id JOIN queue q
ON q.queueid = s.queueid
Where q.active = 'Y' and a.active = 'Y' and s.period BETWEEN '03/01/2004' and '05/01/2004' and s.callscompleted <> 0
order by queue, agent

Result:

Queue Agent March April May

Phones Bob 98 NULL NULL
Phones Bob NULL 95 NULL
Phones Bob NULL NULL 92

I don't want to display the NULL entries. I want it to look like:

Result:

Queue Agent March April May
Phones Bob 98 95 92

Please help!

X002548
Not Just a Number

15586 Posts

Posted - 2004-06-24 : 14:27:01
You sure that runs?


SELECT Queue, Agent, AVG(March) AS AVG_March, AVG(April) AS AVG_April, AVG(March) AS AVG_May
FROM (
SELECT q.[description] AS Queue
, a.firstName + ' ' + a.lastname AS Agent
, (select s.score where s.period='03/01/2004') AS March
, (select s.score where s.period='04/01/2004') AS April
, (select s.score where s.period='05/01/2004') AS May
FROM agent a
LEFT JOIN service_level_report s
ON a.id = s.id
JOIN queue q
ON q.queueid = s.queueid
WHERE q.active = 'Y'
AND a.active = 'Y'
AND s.period BETWEEN '03/01/2004' AND '05/01/2004'
AND s.callscompleted <> 0
) AS XXX
GROUP BY Queue, Agent





Brett

8-)
Go to Top of Page

ladiaocb
Yak Posting Veteran

57 Posts

Posted - 2004-06-24 : 14:38:49
Brett,

It did work, it was just really ugly.

I tried your query and it worked great!!! Thanks for your help!
Go to Top of Page
   

- Advertisement -