Duplicate Results in Result View

Topics: Developer Forum
Feb 12, 2013 at 9:50 PM
Edited Feb 12, 2013 at 9:52 PM
When executing the sql query
select * from [LMS RESULT VIEW] 
against the SharePointLearningKit Database every returned result is duplicated.


I realize I can just use
Select distinct(id),Question, "Result (sort)", InteractionType, "Answer (Yes/No)", "Answer (string)", "Answer (numeric)", ActivityAttemptId, Student, Instructor, AssignmentId, Assignment, Result from [LMS RESULT VIEW]
but if the view is duplicating data I'm not sure if I trust the view at all

For example in my database there are 450 unique entries but 900 total. This duplication only occurs on the dbo.LMS Result View. I went through the default script for the view and can't pick out the error. Maybe someone else can spot it.
USE [SharePointLearningKit]
GO

/****** Object:  View [dbo].[LMS Result View]    Script Date: 02/12/2013 14:23:23 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[LMS Result View]
AS
SELECT     dbo.InteractionItem.Id, dbo.InteractionItem.Description AS Question, dbo.ResultState.Name AS [Result (sort)], dbo.InteractionType.Name AS InteractionType, 
                      dbo.InteractionItem.LearnerResponseBool AS [Answer (Yes/No)], dbo.InteractionItem.LearnerResponseString AS [Answer (string)], 
                      dbo.InteractionItem.LearnerResponseNumeric AS [Answer (numeric)], dbo.InteractionItem.ActivityAttemptId, '-1;#' + UserItem_1.Name AS Student, 
                      dbo.GetInstructors(dbo.LearnerAssignmentItem.AssignmentId) AS Instructor, dbo.AssignmentItem.Id AS AssignmentId, 
                      'http://<redacted servername>/_layouts/SharePointLearningKit/Grading.aspx?AssignmentId=' + CAST(dbo.AssignmentItem.Id AS VARCHAR(255)) 
                      + ', ' + dbo.AssignmentItem.Title + ' (#' + CAST(dbo.AssignmentItem.Id AS VARCHAR(255)) + ')' AS Assignment, dbo.ResultState.FormattedName AS Result
FROM         dbo.ActivityAttemptItem INNER JOIN
                      dbo.UserItem AS UserItem_1 INNER JOIN
                      dbo.AttemptItem INNER JOIN
                      dbo.AssignmentItem INNER JOIN
                      dbo.LearnerAssignmentItem ON dbo.AssignmentItem.Id = dbo.LearnerAssignmentItem.AssignmentId ON 
                      dbo.AttemptItem.LearnerAssignmentId = dbo.LearnerAssignmentItem.Id ON UserItem_1.Id = dbo.LearnerAssignmentItem.LearnerId ON 
                      dbo.ActivityAttemptItem.AttemptId = dbo.AttemptItem.Id RIGHT OUTER JOIN
                      dbo.InteractionItem INNER JOIN
                      dbo.InteractionType ON dbo.InteractionItem.InteractionType = dbo.InteractionType.Id INNER JOIN
                      dbo.ResultState ON dbo.InteractionItem.ResultState = dbo.ResultState.Id ON dbo.ActivityAttemptItem.Id = dbo.InteractionItem.ActivityAttemptId

GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "ActivityAttemptItem"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 125
               Right = 238
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "UserItem_1"
            Begin Extent = 
               Top = 6
               Left = 276
               Bottom = 125
               Right = 443
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "AttemptItem"
            Begin Extent = 
               Top = 6
               Left = 481
               Bottom = 125
               Right = 672
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "AssignmentItem"
            Begin Extent = 
               Top = 6
               Left = 710
               Bottom = 125
               Right = 920
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "LearnerAssignmentItem"
            Begin Extent = 
               Top = 6
               Left = 958
               Bottom = 125
               Right = 1145
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "InteractionItem"
            Begin Extent = 
               Top = 6
               Left = 1183
               Bottom = 125
               Right = 1394
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "InteractionType"
            Begin Extent = 
               Top = 126
               Left = 38
               Bottom = 215
               Right = 1' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'LMS Result View'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane2', @value=N'98
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "ResultState"
            Begin Extent = 
               Top = 126
               Left = 236
               Bottom = 230
               Right = 402
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'LMS Result View'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=2 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'LMS Result View'
GO
Coordinator
Mar 5, 2013 at 7:33 PM
That view is very difficult to read with the ON clauses separated from the JOINs. I could only get it to run by commenting out the ResultTable and GetInstructors, at which point I'm only getting one line per item.

I would suggest starting with a single table and adding one at a time until you get the duplicate. Unless your data is the problem, it is likely to be ResultTable or GetInstructors as I wasn't able to test them.

Richard
SLK Coordinator
http://blog.salamandersoft.co.uk