Author |
Topic |
sz1
Aged Yak Warrior
555 Posts |
Posted - 2012-03-21 : 09:03:22
|
HeyI have another issue with this query. I'm getting too many counts but this is because the t.[OwnerTeam] = 'Sales' can appear multiple times assignment wise. so, think I need another distinct or count only once when Sales record found in OwnerTeam NOT Multiple...can someone advise?ThanksALTER View [dbo].[STCalls]ASSELECT COUNT(Distinct i.[IncidentNumber]) As [Live ITSM Calls]FROMdbo.Incident AS iJoin dbo.Task AS t ON i.[Recid] = t.[ParentLink_RecID]Wherei.[Status] IN ('Active','Waiting')And t.[OwnerTeam] = 'Sales'GO |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-21 : 10:22:22
|
we cant suggest anything unless we see some data and understand what you're talking about. You already have count(distinct ...) and if its not working show some data and explain what count you're expecting out of them------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
sz1
Aged Yak Warrior
555 Posts |
Posted - 2012-03-21 : 11:20:09
|
thats fair enough, I've just run this and I know whats happening now.I'm getting more records back because the sales team has an Incident somewhere in the record, so If I could only say give me the last record (the one which is live) that = sales then that would do it. Tried putting a MAX in front as below but still getting same result, thought that would have done it as Max should be the last record = sales?Does this help?ALTER View [dbo].[SDCalls]ASSELECT i.[IncidentNumber],Max(t.[OwnerTeam]) As [OwnerTeam],i.[Status],COUNT(Distinct i.[IncidentNumber]) As [LiveCalls]FROM dbo.Incident AS i Join dbo.Task AS t ON i.[Recid] = t.[ParentLink_RecID]Where i.[Status] IN ('Active','Waiting') and t.[OwnerTeam] = 'Sales'Group byi.IncidentNumber,i.Status,t.OwnerTeamGO |
 |
|
X002548
Not Just a Number
15586 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-21 : 12:15:58
|
quote: Originally posted by sz1 thats fair enough, I've just run this and I know whats happening now.I'm getting more records back because the sales team has an Incident somewhere in the record, so If I could only say give me the last record (the one which is live) that = sales then that would do it. Tried putting a MAX in front as below but still getting same result, thought that would have done it as Max should be the last record = sales?Does this help?ALTER View [dbo].[SDCalls]ASSELECT i.[IncidentNumber],Max(t.[OwnerTeam]) As [OwnerTeam],i.[Status],COUNT(Distinct i.[IncidentNumber]) As [LiveCalls]FROM dbo.Incident AS i Join dbo.Task AS t ON i.[Recid] = t.[ParentLink_RecID]Where i.[Status] IN ('Active','Waiting') and t.[OwnerTeam] = 'Sales'Group byi.IncidentNumber,i.Status,t.OwnerTeamGO
again this query makes no sense to us as we dont know how tables are related and have no idea of data it containsso please post what Brett has asked for and then somebody will be able to help------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
sz1
Aged Yak Warrior
555 Posts |
Posted - 2012-03-22 : 08:08:09
|
Ok, I've looked thru an old view I created and its the CreatedDateTime field from the Task table I need to be the last record so I need to Max this for the last record that = 'ServiceDesk'Here is some data with the duplicates (the duplicates are other teams, dont want other records just one unique, I know my Distinct clause is doing nothing!)Meed to just show the last record from the CreateddateTime fieldIncidentNum1709 2009-04-30 14:14:57.000 Service Desk Waiting 11952 2009-05-01 10:10:22.000 Service Desk Waiting 11956 2009-05-01 10:13:24.000 Service Desk Waiting 11958 2009-05-01 10:16:25.000 Service Desk Waiting 11971 2009-05-01 10:39:52.000 Service Desk Waiting 11975 2009-05-01 10:45:02.000 Service Desk Waiting 11987 2009-05-01 11:01:07.000 Service Desk Waiting 11989 2009-05-01 11:06:21.000 Service Desk Waiting 11993 2009-05-01 11:11:19.000 Service Desk Waiting 11994 2009-05-01 11:13:40.000 Service Desk Waiting 11997 2009-05-01 11:15:59.000 Service Desk Waiting 12013 2009-05-01 11:46:48.000 Service Desk Waiting 12016 2009-05-01 11:49:07.000 Service Desk Waiting 12021 2009-05-01 11:57:08.000 Service Desk Waiting 12022 2009-05-01 11:59:25.000 Service Desk Waiting 12025 2009-05-01 12:02:19.000 Service Desk Waiting 12026 2009-05-01 12:09:49.000 Service Desk Waiting 14561 2009-05-13 11:39:48.000 Service Desk Waiting 16182 2009-05-20 10:49:07.000 Service Desk Waiting 118145 2009-07-14 13:42:24.000 Service Desk Waiting 118145 2009-07-14 15:42:20.000 Service Desk Waiting 1--want this one, thought the Max would do it?USE [IT1]GO/****** Object: View [dbo].[SDeskCalls] Script Date: 03/22/2012 11:38:04 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER View [dbo].[SDeskCalls]ASSELECT i.[IncidentNumber],Max(t.[CreatedDateTime]) As LastAssignment, --only show last recordt.[OwnerTeam],i.[Status],COUNT(Distinct i.[IncidentNumber]) As [Live ITSM Calls]FROM dbo.Incident AS i Join dbo.Task AS t ON i.[Recid] = t.[ParentLink_RecID]Where i.[Status] IN ('Active','Waiting') and t.[OwnerTeam] = 'Service Desk' --and t.[OwnerTeam] Not In ('Asset Management','Systems')Group byi.IncidentNumber,t.CreatedDateTime,i.Status,t.OwnerTeam--Order By i.[IncidentNumber]--select * from [SDeskCalls]GO |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-22 : 15:40:06
|
so count should come as 1 or 2?USE [IT1]GO/****** Object: View [dbo].[SDeskCalls] Script Date: 03/22/2012 11:38:04 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER View [dbo].[SDeskCalls]ASSELECT i.[IncidentNumber],Max(t.[CreatedDateTime]) As LastAssignment, --only show last recordt.[OwnerTeam],i.[Status],COUNT(Distinct i.[IncidentNumber]) As [Live ITSM Calls]FROMdbo.Incident AS iJoin dbo.Task AS t ON i.[Recid] = t.[ParentLink_RecID]Wherei.[Status] IN ('Active','Waiting')and t.[OwnerTeam] = 'Service Desk'--and t.[OwnerTeam] Not In ('Asset Management','Systems')Group byi.IncidentNumber,i.Status,t.OwnerTeam--Order By i.[IncidentNumber]--select * from [SDeskCalls]GO ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
sz1
Aged Yak Warrior
555 Posts |
Posted - 2012-03-22 : 16:09:50
|
Well you could say that..for the incident number below "18145" there are 2 records that = Service Desk, but there could be multiple records, you could say each time one is found for that team count up so 1,2,3...but there are other teams that have records too, I just want to say give me the latest/last CreatedDateTime record = Service Desk, so all other records with another team that is last I dont want to see.Any good?18145 2009-07-14 13:42:24.000 Service Desk Waiting 118145 2009-07-14 15:42:20.000 Service Desk Waiting 1 |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|