Guest User

Untitled

a guest
Oct 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.69 KB | None | 0 0
  1. USE [SDS_DevSchoolDistrict]
  2. GO
  3. /****** Object:  UserDefinedFunction [dbo].[CurrentStudentsForStudentGroupAssignment]    Script Date: 09/02/2011 18:40:45 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8.  
  9. ALTER FUNCTION [dbo].[CurrentStudentsForStudentGroupAssignment](
  10.     @PersonId int, @StudentGroupId int = NULL
  11. )
  12. --DECLARE @OutputTable TABLE
  13. RETURNS @OutputTable TABLE
  14. (       ------------------------------------------
  15.         StudentId           int NULL,
  16.         Student             varchar(300) NULL,
  17.         Ssid                varchar(20) NULL,
  18.  
  19.         LastName            Name NOT NULL,
  20.         FirstName           Name NULL,
  21.         MiddleName          Name NULL,
  22.         NickName            Name NULL,
  23.         BirthDate           BirthDate NULL,
  24.         Gender              GenderAbbreviation NULL,
  25.  
  26.         --SchoolYear        varchar(11) NULL,
  27.         CurrentGradeLevel   varchar(100) NULL,
  28.         CurrentSchool       varchar(100) NULL/*,
  29.        
  30.         StudentIsEll        bit NULL,
  31.         IsSpecialEducation  bit NULL,
  32.         IsHighlyCapabale    bit NULL,
  33.         IsTitleOneLap       bit NULL*/
  34. )       ------------------------------------------
  35. AS
  36. BEGIN
  37.         ----------------------------------------------------
  38.         -- Calcualte default for SchoolYear
  39.         ----------------------------------------------------
  40.         DECLARE @SchoolYearId int
  41.         SET @SchoolYearId = dbo.SchoolYearIdValue(GETDATE())
  42.         ----------------------------------------------------
  43.  
  44.         INSERT  @OutputTable
  45.         (       StudentId,
  46.                 Student,
  47.                 Ssid,
  48.  
  49.                 LastName,
  50.                 FirstName,
  51.                 MiddleName,
  52.                 NickName,
  53.                 BirthDate,
  54.                 Gender,
  55.  
  56.             --  SchoolYear,
  57.                 CurrentGradeLevel,
  58.                 CurrentSchool/*,
  59.                
  60.                 StudentIsEll,
  61.                 IsSpecialEducation,
  62.                 IsHighlyCapabale,
  63.                 IsTitleOneLap*/
  64.         )
  65.         SELECT  S.StudentId,
  66.                 S.Student,
  67.                 S.Ssid,
  68.                 P.LastName,
  69.                 P.FirstName,
  70.                 P.MiddleName,
  71.                 P.NickName,
  72.                 P.BirthDate,
  73.                 P.Gender,
  74.             --  SY.SchoolYear,
  75.                 GL.GradeLevel,
  76.                 Sc.School/*,
  77.                 0 AS StudentIsEll,
  78.                 0 AS IsSpecialEducation,
  79.                 0 AS IsHighlyCapabale,
  80.                 0 AS IsTitleOneLap*/
  81.         FROM    SpotlightableStudentsByPerson(@PersonId, DEFAULT, DEFAULT) SS
  82.         JOIN    Students S
  83.           ON    SS.StudentId = S.StudentId
  84.         JOIN    Persons  P
  85.           ON    S.StudentId = P.PersonId
  86.         JOIN    StudentSchoolYears SSY
  87.           ON    S.StudentId = SSY.StudentId
  88.          AND    SSY.SchoolYearId = @SchoolYearId
  89.         JOIN    SchoolYears SY
  90.           ON    SSY.SchoolYearId = SY.SchoolYearId
  91.         JOIN    Schools Sc
  92.           ON    SSY.PredominantSchoolId = Sc.SchoolId  
  93.         JOIN    GradeLevels GL
  94.           ON    SSY.GradeLevelId = GL.GradeLevelId
  95.         WHERE   S.StudentId NOT IN (
  96.                         SELECT  S_G.StudentId
  97.                         FROM    Students_Groups S_G
  98.                         WHERE   S_G.StudentGroupId = @StudentGroupId   
  99.                 )        
  100.        
  101.          
  102.         ORDER
  103.            BY   P.LastName
  104.         ----------------------------------
  105.         --SELECT * FROM @OutputTable
  106.         ----------------------------------
  107.  
  108.  
  109.  
  110.     RETURN
  111. END
Add Comment
Please, Sign In to add comment