Guest User

Untitled

a guest
Apr 13th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.92 KB | None | 0 0
  1. USE [SDS_DevSchoolDistrict]
  2. GO
  3. /****** Object:  UserDefinedFunction [dbo].[StudentGroupCandidatesSearchResults]    Script Date: 04/13/2012 18:45:35 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8.  
  9.  
  10. --SELECT * FROM ProfileLookupSearchResults('Acierto')
  11. -- GO
  12.  
  13. --SELECT * FROM DistrictAdministrators
  14. --SELECT * FROM [StudentGroupCandidatesSearchResults]('smith', DEFAULT, DEFAULT, DEFAULT, 357, 1)
  15. ALTER FUNCTION [dbo].[StudentGroupCandidatesSearchResults]
  16. (
  17.     @SearchText         varchar(100) = '',
  18. --  @EntityTypeId       int = NULL,-- 1 (School District), 2 (School), 3 (Class), 4 (Family), 5 (Activity), or 6 (Person)
  19. --  @PersonRoleId       int = NULL, -- 'Teacher', 'Student', 'Guardian', 'Specialist', 'School Administrator', or 'District Administrator'
  20.     @RestrictToCurrent  bit = 1,
  21.     @StudentGroupId     int = NULL,
  22.     ---------------------------------------------------
  23.     @DataViewMode       varchar(200) = 'Standard',
  24.     @EncryptIds         bit = 0,
  25.     @ApplicationUserId  int = NULL,
  26.     @ApplicationUserPersonRoleId int = 1
  27. )
  28. --DECLARE  @OutputTable TABLE
  29. RETURNS @OutputTable TABLE
  30. (
  31.     studentId                   ElementId,
  32.     Ordinal             int,
  33.     [Text]              varchar(500),
  34.     displayName         varchar(500),
  35.     Description         varchar(500),
  36.     ImagePath           varchar(500),
  37.     Gender              char(1)
  38. )
  39. AS
  40. BEGIN   -- =============================================================================*/
  41.  
  42.         /*----------------------------------------------
  43.         -- Debugging
  44.         -----------------------------------------------
  45.         DECLARE @SearchText         varchar(100) = 'John'
  46.         DECLARE @RestrictToCurrent bit = 1
  47.         DECLARE @DataViewMode       varchar(200) = 'Demonstration'
  48.         DECLARE @EncryptIds         bit
  49.         DECLARE @ApplicationUserId  int = 357
  50.         DECLARE @ApplicationUserPersonRoleId int = 1
  51.         -----------------------------------------------*/
  52.  
  53.  
  54.  
  55.  
  56.         ----------------------------------------------
  57.         --
  58.         -----------------------------------------------
  59.         DECLARE @EntityTypeId int = 6 -- Person
  60.         DECLARE @PersonRoleId int = 8 -- Student
  61.         -----------------------------------------------
  62.  
  63.  
  64.  
  65.  
  66.  
  67.         ----------------------------------------------
  68.         --
  69.         -----------------------------------------------
  70.         INSERT  @OutputTable (
  71.                 studentId,
  72.                 Text,
  73.                 DisplayName,
  74.                 Gender,
  75.                 Description,
  76.                 Ordinal
  77.         )
  78.         SELECT  EntityId,
  79.                 EntityName,
  80.                 EntityName,
  81.                 Gender,
  82.                 PersonRoleDesc,
  83.                 ROW_NUMBER() OVER (ORDER BY R.EntityOrderingText) AS Ordinal
  84.         FROM    ProfileLookupSearchResults(@SearchText, @EntityTypeId, @PersonRoleId, @RestrictToCurrent, @DataViewMode, @EncryptIds, @ApplicationUserId, @ApplicationUserPersonRoleId) R
  85.         WHERE   NOT EXISTS (
  86.                     SELECT  1
  87.                     FROM    Students_Groups S_G
  88.                     WHERE   S_G.StudentGroupId = @StudentGroupId
  89.                       AND   S_G.StudentId = R.EntityId
  90.                 )
  91.         ORDER
  92.             BY  6
  93.         -----------------------------------------------
  94.  
  95.  
  96.  
  97.         --SELECT * FROM @OutputTable
  98. RETURN  -- =============================================================================
  99. END
Advertisement
Add Comment
Please, Sign In to add comment