Guest User

Untitled

a guest
Mar 28th, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 4.25 KB | None | 0 0
  1. USE [SDS_DevSchoolDistrict]
  2. GO
  3. -- =============================================
  4. -- Author:      School Data Solutions
  5. -- Create date: <Create Date, ,>
  6. -- Description: <Description, ,>
  7. -- Copyright 2011-2012 School Data Solutions, All Rights Reserved
  8. -- =============================================
  9. ALTER FUNCTION [dbo].[AssessmentTestsByAssessmentTestGroupAsXml]
  10. (   ---------------------------------------------
  11.     @AssessmentTestGroupId      int,
  12.     ---------------------------------------------
  13.     @DataViewMode       varchar(200) = 'Standard',
  14.     @EncryptIds         bit = 0,
  15.     @ApplicationUserId  int = NULL,
  16.     @ApplicationUserPersonRoleId int = 1
  17. )   ---------------------------------------------
  18. RETURNS Xml
  19. AS
  20. BEGIN   /*---------------------------------------------
  21.         --SELECT * FROM StudentGroups SG JOIN Entities E ON SG.EntityId = E.EntityId WHERE E.EntityTypeId = 1
  22.         SELECT COUNT(AssessmentTestId), AssessmentTestGroupId FROM AssessmentTests_Groups GROUP BY AssessmentTestGroupId ORDER BY 1 DESC
  23.         SELECT dbo.AssessmentTestsByAssessmentTestGroupAsXml(255, DEFAULT, 0, 357, 1)
  24.         DECLARE @StudentGroupId     int = 179
  25.         DECLARE @DataViewMode       varchar(200) = 'Standard'
  26.         DECLARE @EncryptIds         bit = 0
  27.         DECLARE @ApplicationUserId  int = 3
  28.         DECLARE @ApplicationUserActivePersonRoleId int = 1
  29.         ---------------------------------------------*/
  30.        
  31.         ---------------------------------------------
  32.         -- Prepare for performance metrics
  33.         ---------------------------------------------
  34.         DECLARE @StartTime time = CAST(GETDATE() as time)
  35.         ---------------------------------------------
  36.        
  37.    
  38.         ---------------------------------------------
  39.         -- Declare the return variable here
  40.         ---------------------------------------------
  41.         DECLARE @Xml XML
  42.         SET     @Xml = '<Xml xmlAssemblyTimeInMilliseconds=""></Xml>'
  43.         ---------------------------------------------
  44.  
  45.  
  46.        
  47.         ---------------------------------------------
  48.         -- Assessment Tests
  49.         ---------------------------------------------
  50.         DECLARE @AssessmentTests XML
  51.         ---------------------------------------------
  52.         SET @AssessmentTests = (
  53.                 SELECT  T.AssessmentTestLabel AS '@AssessmentTestLabel',
  54.                         T.AssessmentTestName AS '@AssessmentTestName',
  55.                         AT_G.AssessmentTestOrdinalByGroup AS '@Ordinal',
  56.                         CASE @EncryptIds
  57.                           WHEN 1
  58.                             THEN CAST(EncryptedAssessmentTestIds.EncryptedId as varchar(200))
  59.                           ELSE   CAST(T.AssessmentTestId as varchar(200))
  60.                         END AS '@AssessmentTestId',
  61.                         CASE @EncryptIds
  62.                           WHEN 1
  63.                             THEN CAST(EncryptedParentAssessmentTestIds.EncryptedId as varchar(200))
  64.                           ELSE   CAST(T.ParentAssessmentTestId as varchar(200))
  65.                         END AS '@ParentAssessmentTestId'
  66.                 FROM    AssessmentTests T
  67.                 JOIN    AssessmentTests_Groups AT_G
  68.                   ON    T.AssessmentTestId = AT_G.AssessmentTestId
  69.                  AND    AT_G.AssessmentTestGroupId = @AssessmentTestGroupId
  70.                 JOIN    EncryptedIds EncryptedAssessmentTestIds
  71.                   ON    T.AssessmentTestId = EncryptedAssessmentTestIds.Id
  72.                 LEFT
  73.                 JOIN    EncryptedIds EncryptedParentAssessmentTestIds
  74.                   ON    T.ParentAssessmentTestId = EncryptedParentAssessmentTestIds.Id
  75.                 ORDER
  76.                    BY   T.AssessmentTestLabel
  77.             --FOR XML AUTO, ROOT('AssessmentTests')  
  78.             FOR XML PATH('AssessmentTest'),ROOT('AssessmentTests')
  79.         )
  80.         ---------------------------------------------
  81.         --SELECT @AssessmentTests AS '@AssessmentTests'
  82.         ---------------------------------------------
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.         ---------------------------------------------
  90.         -- Assemble output Xml
  91.         ---------------------------------------------
  92.         SET @Xml = dbo.XmlAdopt(@Xml,@AssessmentTests,'Xml','AssessmentTest')
  93.         ---------------------------------------------
  94.  
  95.  
  96.  
  97.         ---------------------------------------------
  98.         -- Track Assembly time
  99.         ---------------------------------------------
  100.         DECLARE @XmlAssemblyTimeInMilliseconds int = DATEDIFF(ms, @StartTime,  CAST(GETDATE() as time))
  101.         SET @Xml = dbo.XmlAssignAttributeValues(@Xml, '//Xml', 'xmlAssemblyTimeInMilliseconds', @XmlAssemblyTimeInMilliseconds)
  102.         ---------------------------------------------
  103.  
  104.  
  105.  
  106.  
  107.         --SELECT @Xml AS '@Xml'
  108.         ---------------------------------------------
  109.         RETURN @Xml
  110. END
  111. GO
  112. SELECT dbo.AssessmentTestsByAssessmentTestGroupAsXml(255, DEFAULT, 0, 357, 1) AS 'TEST AssessmentTestsByAssessmentTestGroupAsXml'
Advertisement
Add Comment
Please, Sign In to add comment