USP_DATAFORMTEMPLATE_VIEW_CURRENTUSERSESSION_STUDENTSELECTION

The load procedure used by the view dataform template "Application User Session Student Selection View"

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN The input ID parameter used to load the fields defined on the form.
@CURRENTAPPUSERID uniqueidentifier IN Input parameter indicating the ID of the current user.
@DATALOADED bit INOUT Output parameter indicating whether or not data was actually loaded.
@STUDENTS xml INOUT STUDENTS

Definition

Copy

CREATE procedure dbo.USP_DATAFORMTEMPLATE_VIEW_CURRENTUSERSESSION_STUDENTSELECTION
(
    @ID uniqueidentifier,
    @CURRENTAPPUSERID uniqueidentifier,
    @DATALOADED bit = 0 output,
    @STUDENTS xml = null output
)
as
    set nocount on;

    -- be sure to set this, in case the select returns no rows
    set @DATALOADED = 0;

    declare @SESSION_STARTDATE date
    declare @SESSION_ENDDATE date

    select
        @SESSION_STARTDATE = min(STARTDATE),
        @SESSION_ENDDATE = max(ENDDATE)
    from dbo.TERM
        inner join dbo.APPUSERSESSION on TERM.SESSIONID = APPUSERSESSION.SESSIONID
    where APPUSERSESSION.ID = @CURRENTAPPUSERID
    group by APPUSERSESSION.ID

    declare @STUDENTLIST table
    (
        ID uniqueidentifier
    )
    insert into @STUDENTLIST (ID)
    exec dbo.USP_STUDENT_GETSTUDENTSELECTION @ID

    if @@ROWCOUNT > 0
    begin
        set @DATALOADED = 1
        set @STUDENTS = (
            select STUDENTLIST.ID
            from @STUDENTLIST STUDENTLIST
                inner join dbo.EDUCATIONALHISTORY on STUDENTLIST.ID = EDUCATIONALHISTORY.CONSTITUENTID
                inner join dbo.STUDENTPROGRESSION on EDUCATIONALHISTORY.ID = STUDENTPROGRESSION.ENROLLMENTID
            where STUDENTPROGRESSION.STARTDATE <= @SESSION_STARTDATE
                and STUDENTPROGRESSION.ENDDATE >= @SESSION_ENDDATE            
            for xml raw('ITEM'),type,elements,root('STUDENTS'),binary base64
        )
    end