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.
Author |
Topic |
sz1
Aged Yak Warrior
555 Posts |
Posted - 2012-12-11 : 10:28:55
|
HiI 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 INTotherwise how do I embed the: select Count(STATUS_NAME)/Count(ID) as Pecent where STATUS_NAME = 'Waiting' it into this:Current statementselect 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_CATEGORYfrom DIM_CALLs cwhere c.OPEN_FLAG = 1 and c.ABC_CURRENT =1AND 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_CATEGORYOrder by "Open Days" DESC, OCCUREDThanks you |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-12 : 00:03:28
|
IncludeSELECT ............,CASE WHEN STATUS_NAME = 'Waiting' THEN Count(STATUS_NAME)/Count(ID) END as PecentFROM DIM_Calls GROUP BY .............--Chandu |
 |
|
sz1
Aged Yak Warrior
555 Posts |
Posted - 2012-12-12 : 04:36:29
|
Thanks Bandi,So I can embed CASE statements like this as part fo existing select statements? thats really handy that...and the CASE can go anywhere in the select clause as long as before the From table...ThnaksS |
 |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-12 : 04:58:09
|
Welcome --Chandu |
 |
|
|
|
|
|
|