dbTalk Databases Forums  

Getting percentage

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Getting percentage in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
JJ297
 
Posts: n/a

Default Getting percentage - 12-15-2009 , 01:40 PM






How do I add the icode to this query to get the percentage of calls
received / calls offered?

select sum(isnull([calls offered],0)) as CO,
sum(isnull([calls received],0)) as CR,
sum(isnull(Answered,0)) as Ans,
sum(isnull(Overflow,0)) as OverFlow,
sum(isnull(Abandoned,0)) as Aband,
sum(isnull(Busy,0)) as Busy, wkdate, dowrdate
from TSRPReport
WHERE Date BETWEEN DATEADD(day, - 4, wkdate) AND wkdate
group by wkdate,dowrdate

Reply With Quote
  #2  
Old   
Plamen Ratchev
 
Posts: n/a

Default Re: Getting percentage - 12-15-2009 , 01:45 PM






Try this:

SELECT SUM(COALESCE([calls offered], 0)) AS CO,
SUM(COALESCE([calls received], 0)) AS CR,
SUM(COALESCE(Answered, 0)) AS Ans,
SUM(COALESCE(Overflow, 0)) AS OverFlow,
SUM(COALESCE(Abandoned, 0)) AS Aband,
SUM(COALESCE(Busy, 0)) AS Busy,
SUM(COALESCE([calls received], 0)) /
NULLIF(SUM(COALESCE([calls offered], 0)), 0) AS perc,
wkdate,
dowrdate
FROM TSRPReport
WHERE [date] BETWEEN DATEADD(day, - 4, wkdate) AND wkdate
GROUP BY wkdate, dowrdate;

--
Plamen Ratchev
http://www.SQLStudio.com

Reply With Quote
  #3  
Old   
JJ297
 
Posts: n/a

Default Re: Getting percentage - 12-15-2009 , 01:48 PM



On Dec 15, 2:45*pm, Plamen Ratchev <Pla... (AT) SQLStudio (DOT) com> wrote:
Quote:
Try this:

SELECT SUM(COALESCE([calls offered], 0)) AS CO,
* * * * SUM(COALESCE([calls received], 0)) AS CR,
* * * * SUM(COALESCE(Answered, 0)) AS Ans,
* * * * SUM(COALESCE(Overflow, 0)) AS OverFlow,
* * * * SUM(COALESCE(Abandoned, 0)) AS Aband,
* * * * SUM(COALESCE(Busy, 0)) AS Busy,
* * * * SUM(COALESCE([calls received], 0)) /
* * * * NULLIF(SUM(COALESCE([calls offered], 0)), 0) AS perc,
* * * * wkdate,
* * * * dowrdate
FROM TSRPReport
WHERE [date] BETWEEN DATEADD(day, - 4, wkdate) AND wkdate
GROUP BY wkdate, dowrdate;

--
Plamen Ratchevhttp://www.SQLStudio.com
No that didn't work it came out as whole numbers and I don't have a
perc column (should I)?

Reply With Quote
  #4  
Old   
JJ297
 
Posts: n/a

Default Re: Getting percentage - 12-15-2009 , 01:52 PM



On Dec 15, 2:45*pm, Plamen Ratchev <Pla... (AT) SQLStudio (DOT) com> wrote:
Quote:
Try this:

SELECT SUM(COALESCE([calls offered], 0)) AS CO,
* * * * SUM(COALESCE([calls received], 0)) AS CR,
* * * * SUM(COALESCE(Answered, 0)) AS Ans,
* * * * SUM(COALESCE(Overflow, 0)) AS OverFlow,
* * * * SUM(COALESCE(Abandoned, 0)) AS Aband,
* * * * SUM(COALESCE(Busy, 0)) AS Busy,
* * * * SUM(COALESCE([calls received], 0)) /
* * * * NULLIF(SUM(COALESCE([calls offered], 0)), 0) AS perc,
* * * * wkdate,
* * * * dowrdate
FROM TSRPReport
WHERE [date] BETWEEN DATEADD(day, - 4, wkdate) AND wkdate
GROUP BY wkdate, dowrdate;

--
Plamen Ratchevhttp://www.SQLStudio.com
Sorry I do see the Perc column but it has all 0's in them.

Reply With Quote
  #5  
Old   
Plamen Ratchev
 
Posts: n/a

Default Re: Getting percentage - 12-15-2009 , 01:55 PM



You can avoid integer division by casting to decimal with correct precision or simply by multiplying by 1.0:

SELECT SUM(COALESCE([calls offered], 0)) AS CO,
SUM(COALESCE([calls received], 0)) AS CR,
SUM(COALESCE(Answered, 0)) AS Ans,
SUM(COALESCE(Overflow, 0)) AS OverFlow,
SUM(COALESCE(Abandoned, 0)) AS Aband,
SUM(COALESCE(Busy, 0)) AS Busy,
1.0 * SUM(COALESCE([calls received], 0)) /
NULLIF(SUM(COALESCE([calls offered], 0)), 0) AS perc,
wkdate,
dowrdate
FROM TSRPReport
WHERE [date] BETWEEN DATEADD(day, - 4, wkdate) AND wkdate
GROUP BY wkdate, dowrdate;

--
Plamen Ratchev
http://www.SQLStudio.com

Reply With Quote
  #6  
Old   
JJ297
 
Posts: n/a

Default Re: Getting percentage - 12-15-2009 , 03:00 PM



On Dec 15, 2:55*pm, Plamen Ratchev <Pla... (AT) SQLStudio (DOT) com> wrote:
Quote:
You can avoid integer division by casting to decimal with correct precision or simply by multiplying by 1.0:

SELECT SUM(COALESCE([calls offered], 0)) AS CO,
* * * * SUM(COALESCE([calls received], 0)) AS CR,
* * * * SUM(COALESCE(Answered, 0)) AS Ans,
* * * * SUM(COALESCE(Overflow, 0)) AS OverFlow,
* * * * SUM(COALESCE(Abandoned, 0)) AS Aband,
* * * * SUM(COALESCE(Busy, 0)) AS Busy,
* * * * 1.0 * SUM(COALESCE([calls received], 0)) /
* * * * NULLIF(SUM(COALESCE([calls offered], 0)), 0) AS perc,
* * * * wkdate,
* * * * dowrdate
FROM TSRPReport
WHERE [date] BETWEEN DATEADD(day, - 4, wkdate) AND wkdate
GROUP BY wkdate, dowrdate;

--
Plamen Ratchevhttp://www.SQLStudio.com
okay thanks I will try it in the morning.

Reply With Quote
  #7  
Old   
JJ297
 
Posts: n/a

Default Re: Getting percentage - 12-16-2009 , 07:36 AM



On Dec 15, 4:00*pm, JJ297 <nc... (AT) yahoo (DOT) com> wrote:
Quote:
On Dec 15, 2:55*pm, Plamen Ratchev <Pla... (AT) SQLStudio (DOT) com> wrote:





You can avoid integer division by casting to decimal with correct precision or simply by multiplying by 1.0:

SELECT SUM(COALESCE([calls offered], 0)) AS CO,
* * * * SUM(COALESCE([calls received], 0)) AS CR,
* * * * SUM(COALESCE(Answered, 0)) AS Ans,
* * * * SUM(COALESCE(Overflow, 0)) AS OverFlow,
* * * * SUM(COALESCE(Abandoned, 0)) AS Aband,
* * * * SUM(COALESCE(Busy, 0)) AS Busy,
* * * * 1.0 * SUM(COALESCE([calls received], 0)) /
* * * * NULLIF(SUM(COALESCE([calls offered], 0)), 0) AS perc,
* * * * wkdate,
* * * * dowrdate
FROM TSRPReport
WHERE [date] BETWEEN DATEADD(day, - 4, wkdate) AND wkdate
GROUP BY wkdate, dowrdate;

--
Plamen Ratchevhttp://www.SQLStudio.com

okay thanks I will try it in the morning.- Hide quoted text -

- Show quoted text -
Thanks so much Plamen that worked!

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.