|
sz1
Constraint Violating Yak Guru
United Kingdom
294 Posts |
Posted - 12/11/2012 : 10:28:55
|
Hi
I have a status field I want to work out an average for, whereby the status = waiting then work out the percentage of waiting against all calls. Can I use a delare statement to work this out?
DECLARE @AvgWaiting INT
otherwise how do I embed the: select Count(STATUS_NAME)/Count(ID) as Pecent where STATUS_NAME = 'Waiting' it into this:
Current statement
select distinct [ID],c.DESC_SHORT,c.STATUS_NAME, c.OCCURED_DT AS "Open Date", DATEDIFF(d, c.OCCURED_DT, GETDATE()) AS "Open Days", AVG(DATEDIFF(d, c.OCCURED_DT, GETDATE())) AS "Day Average", c.ASSIGNED_Team_NAME, c.ASSIGNED_REP_NAME, c.PRIORITY_NAME, TYPE, [SYMPTOM], [CONTACT_FIRST_NAME] + ' ' + [CONTACT_LAST_NAME] AS "Contact Name", INTI_CATEGORY from DIM_CALLs c where c.OPEN_FLAG = 1 and c.ABC_CURRENT =1 AND TYPE ='Incident'
Group By [ID], c.DESC_SHORT, c.STATUS_NAME, c.OCCURED_DT, c.ASSIGNED_Team_NAME, c.ASSIGNED_REP_NAME, c.PRIORITY_NAME, TYPE, SYMPTOM, CONTACT_FIRST_NAME, CONTACT_LAST_NAME, INTI_CATEGORY
Order by "Open Days" DESC, OCCURED
Thanks you
|
Edited by - sz1 on 12/11/2012 10:29:59
|
|