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 |
|
emailuser
Yak Posting Veteran
74 Posts |
Posted - 2011-02-18 : 08:08:23
|
| Hi I am calculating the number of telephone calls taken by a department and the number of tickets logged by that department, the department aim is to have the same number of tickets as telephone calls , my script below give me this information from now going back 7 days, what would be really nice is to calcualte the percentage of tickets logged v the number of telephone calls, telephone calls will always be the reference point, i have spent several hours trying to work it out but i just cant see how to do it ... again any help massively appreciated :)SELECT COUNT(ccmdb1.dbo.agent.agent_name),agent_activity_cur.date_from,SUM(agent_activity_cur.acd_grp_conv_call_cnt) AS ACDCALLS, (SELECT COUNT(supportdeskdev.suppdeskdev.F0004_SUPEVENT.REFERENCE)FROM supportdeskdev.suppdeskdev.F0004_SUPEVENTWHERE supportdeskdev.suppdeskdev.F0004_SUPEVENT.OPENDATE = agent_activity_cur.date_from and supportdeskdev.suppdeskdev.F0004_SUPEVENT.CUSTOMERREF <>'Premium'GROUP BY supportdeskdev.suppdeskdev.F0004_SUPEVENT.OPENDATE) as HOTHFROM agent INNER JOIN agent_activity_curON ccmdb1.dbo.agent.agent_id = agent_activity_cur.agent_idwhere agent_activity_cur.date_from >getdate()-10 and agent_activity_cur.agent_grp_id='16' GROUP BY datepart(day,agent_activity_cur.date_from), agent_activity_cur.date_fromHAVING (sum(acd_grp_conv_call_cnt + acd_dir_conv_call_cnt)) <>'0'ORDER BY date_from DESC |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-18 : 14:08:53
|
Perhaps it would be helpful if you could come up with table(s) structure, few data rows (for every table in your above query) and the desired output format in light of those information.. as its hard to understand for me at least about your requirements from your above query |
 |
|
|
emailuser
Yak Posting Veteran
74 Posts |
Posted - 2011-02-21 : 12:30:07
|
| Hi MIKhere is some data and structure hope this helpsDB : Supportdeskdev table F0004_SUPEVENTCUSTOMERREF CATTYPE CATSTATUS CATPRIORITY SUPPORTTAG OPENDATE CLOSEDATE TITLEAlarm Supplies 942 27 0 Mchamb 04/02/2010 00:00 04/02/2010 00:00 price queryCity Fire 942 27 0 Ranil 04/02/2010 00:00 04/02/2010 00:00 price queryFire 942 27 0 Mchamb 04/02/2010 00:00 04/02/2010 00:00 price queryTF ltd 942 27 0 Ranil H 01/02/2010 00:00 01/02/2010 00:00 price queryDB : CCMDB1 table agent_activity_curagent_id date_from time_from time_to agent_grp_id acd_grp_conv_call_cnt2 01/03/2004 00:00 01/01/1900 00:00 01/01/1900 00:15 2 52 01/03/2004 00:00 01/01/1900 00:15 01/01/1900 00:30 2 52 01/03/2004 00:00 01/01/1900 00:30 01/01/1900 00:45 2 02 01/03/2004 00:00 01/01/1900 00:45 01/01/1900 01:00 2 12 01/03/2004 00:00 01/01/1900 01:00 01/01/1900 01:15 2 0DATABASE :ccmdb1 Table dbo.agentagent_id: agent_num: agent_name: agent_grp_id: active_date: inactive_date:66 92 AB 14 24/11/2004 00:00 01/01/2035 00:0085 39 A Brewin 18 22/03/2006 00:00 14/01/2010 00:00129 2 A Fels 4 26/03/2010 00:00 01/01/2035 00:0062 12 Anelia 26 04/11/2002 00:00 01/01/2035 00:00Desired output format would be Date: Count of telephone calls taken : Count of helpdesk tickets logged : Percent of tickets logged v calls taken (helpdesktickets/telephone calls taken ):Hope this makes sense ? ... |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-21 : 13:09:52
|
No , as per given data can you provide the values for the desired output fields? And if possible also explain as how you extracted that output. this will help the folks in this forum to manipulate it for you via Transact SQL (including me - if i could) hope you are getting what i am asking for CheersMIK |
 |
|
|
jcelko
Esteemed SQL Purist
547 Posts |
Posted - 2011-02-21 : 19:56:23
|
| Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. If you know how, follow ISO-11179 data element naming conventions AND formatting rules. Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible AND not local dialect. Sample data is also a good idea, along with clear specifications. It is very hard to debug code when you do not let us see it. If you want to learn how to ask a question on a Newsgroup, look at: http://www.catb.org/~esr/faqs/smart-questions.htmlyou are being very rude.--CELKO--Books in Celko Series for Morgan-Kaufmann PublishingAnalytics and OLAP in SQLData and Databases: Concepts in Practice Data, Measurements and Standards in SQLSQL for SmartiesSQL Programming Style SQL Puzzles and Answers Thinking in SetsTrees and Hierarchies in SQL |
 |
|
|
emailuser
Yak Posting Veteran
74 Posts |
Posted - 2011-02-22 : 05:55:17
|
Hi Mik, hopefully i am understanding what you are asking for : the sql syntax is SELECT COUNT(ccmdb1.dbo.agent.agent_name),agent_activity_cur.date_from,SUM(agent_activity_cur.acd_grp_conv_call_cnt) AS ACDCALLS, (SELECT COUNT(supportdeskdev.suppdeskdev.F0004_SUPEVENT.REFERENCE)FROM supportdeskdev.suppdeskdev.F0004_SUPEVENTWHERE supportdeskdev.suppdeskdev.F0004_SUPEVENT.OPENDATE = agent_activity_cur.date_from and supportdeskdev.suppdeskdev.F0004_SUPEVENT.CUSTOMERREF <>'Premium'GROUP BY supportdeskdev.suppdeskdev.F0004_SUPEVENT.OPENDATE) as HOTHFROM agent INNER JOIN agent_activity_curON ccmdb1.dbo.agent.agent_id = agent_activity_cur.agent_idwhere agent_activity_cur.date_from >getdate()-10 and agent_activity_cur.agent_grp_id='16' GROUP BY datepart(day,agent_activity_cur.date_from), agent_activity_cur.date_fromHAVING (sum(acd_grp_conv_call_cnt + acd_dir_conv_call_cnt)) <>'0'ORDER BY date_from DESC ** the approach is to count the ACDCALLS - these are telephone calls , by summing the call count for each telephone agenti obtain ACDCALLS ie the number of calls taken by agentI then count the number of helpdesk tickets ( F0004_SUPEVENT_REFERENCE)the WHERE statement matches up the date on when the callwas taken (date_from)and the helpdesk ticket opened ( OPENDATE),i exclude Premium as these are calls we want to exludeI use an inner join as i need to only view telephone calls where the agent_id belongs to agent_grp_id='16' this allows me only to see data for a specific group of telephone operators.Using getdate to only show me last 10 days and the Having statement to not show we where there is a zero count ( as i know this is a weekend )**My Output is shown below nocolumnname date_from ACDCALLS HOTH29 2011-02-22 00:00:00 111 10951 2011-02-18 00:00:00 137 13768 2011-02-17 00:00:00 114 11383 2011-02-16 00:00:00 140 13983 2011-02-15 00:00:00 120 119118 2011-02-14 00:00:00 117 117 what i am hoping to achieve is an extra colum PERCENT showing the percent of ACDCALLS and HOTHnocolumnname date_from ACDCALLS HOTH Percent29 2011-02-22 00:00:00 111 109 9851 2011-02-18 00:00:00 137 137 10068 2011-02-17 00:00:00 114 113 9983 2011-02-16 00:00:00 140 139 9983 2011-02-15 00:00:00 120 119 99118 2011-02-14 00:00:00 117 117 100 |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-22 : 07:59:05
|
| Select nocolumnname ,date_from ,ACDCALLS ,HOTH ,Cast((HOTH/cast(ACDCALLS as Numeric(6,3)))*100 as Int) as PercentageFrom ( Your Select Query Here) A |
 |
|
|
emailuser
Yak Posting Veteran
74 Posts |
Posted - 2011-02-22 : 08:54:43
|
Hi MIK, really appreciate your quick reply , as a newbie i hope i have interpreted your reply correctly , but i get the following error ... Msg 8155, Level 16, State 2, Line 1No column was specified for column 1 of 'A'. Select nocolumnname,date_from,ACDCALLS,HOTH,Cast((HOTH/cast(ACDCALLS as Numeric(6,3)))*100 as Int) as PercentageFrom (SELECT COUNT(ccmdb1.dbo.agent.agent_name),agent_activity_cur.date_from,SUM(agent_activity_cur.acd_grp_conv_call_cnt) AS ACDCALLS, (SELECT COUNT(supportdeskdev.suppdeskdev.F0004_SUPEVENT.REFERENCE)FROM supportdeskdev.suppdeskdev.F0004_SUPEVENTWHERE supportdeskdev.suppdeskdev.F0004_SUPEVENT.OPENDATE = agent_activity_cur.date_from and supportdeskdev.suppdeskdev.F0004_SUPEVENT.CUSTOMERREF <>'Premium'GROUP BY supportdeskdev.suppdeskdev.F0004_SUPEVENT.OPENDATE) as HOTHFROM agent INNER JOIN agent_activity_curON ccmdb1.dbo.agent.agent_id = agent_activity_cur.agent_idwhere agent_activity_cur.date_from >getdate()-10 and agent_activity_cur.agent_grp_id='16' GROUP BY datepart(day,agent_activity_cur.date_from), agent_activity_cur.date_fromHAVING (sum(acd_grp_conv_call_cnt + acd_dir_conv_call_cnt)) <>'0') A |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-22 : 12:20:13
|
quote: Originally posted by emailuser Hi MIK, really appreciate your quick reply , as a newbie i hope i have interpreted your reply correctly , but i get the following error ... Msg 8155, Level 16, State 2, Line 1No column was specified for column 1 of 'A'. Select nocolumnname,date_from,ACDCALLS,HOTH,Cast((HOTH/cast(ACDCALLS as Numeric(6,3)))*100 as Int) as PercentageFrom (SELECT COUNT(ccmdb1.dbo.agent.agent_name) as noColumnName,agent_activity_cur.date_from,SUM(agent_activity_cur.acd_grp_conv_call_cnt) AS ACDCALLS, (SELECT COUNT(supportdeskdev.suppdeskdev.F0004_SUPEVENT.REFERENCE)FROM supportdeskdev.suppdeskdev.F0004_SUPEVENTWHERE supportdeskdev.suppdeskdev.F0004_SUPEVENT.OPENDATE = agent_activity_cur.date_from and supportdeskdev.suppdeskdev.F0004_SUPEVENT.CUSTOMERREF <>'Premium'GROUP BY supportdeskdev.suppdeskdev.F0004_SUPEVENT.OPENDATE) as HOTHFROM agent INNER JOIN agent_activity_curON ccmdb1.dbo.agent.agent_id = agent_activity_cur.agent_idwhere agent_activity_cur.date_from >getdate()-10 and agent_activity_cur.agent_grp_id='16' GROUP BY datepart(day,agent_activity_cur.date_from), agent_activity_cur.date_fromHAVING (sum(acd_grp_conv_call_cnt + acd_dir_conv_call_cnt)) <>'0') A
:) give a name to the highlighted in red column as required. And replace the Blued one with that name .. OR I have named it as NoColumnName in the above qouted code so if no specific name needs to be given then use the above qouted code |
 |
|
|
emailuser
Yak Posting Veteran
74 Posts |
Posted - 2011-02-23 : 04:35:23
|
| Hi MIK you are a star that worked a treat really appreciate you help and patience ... many many thanks |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-23 : 04:39:26
|
| you're welcome! CheersMIK |
 |
|
|
|
|
|
|
|