[
    ~[tlist_sql; 
        SELECT
            ((TO_DATE('~(gpv.endDate;onlydatecharacters)','~[dateformat]')) - (TO_DATE('~(gpv.startDate;onlydatecharacters)','~[dateformat]')-1)) - COUNT(PS_Membership_Reg.CalendarDate) - (SELECT COUNT(Date_Value) FROM Calendar_Day WHERE InSession = 0 AND SchoolID = ~(curschoolid) AND (Date_Value) BETWEEN TO_DATE('~(gpv.startDate;onlydatecharacters)','~[dateformat]') AND (TO_DATE('~(gpv.endDate;onlydatecharacters)','~[dateformat]'))) as dne,
            PS_Membership_Reg.StudentID,
            Students.DCID,
            TO_CHAR(PS_Enrollment.EntryDate, '~[dateformat]') as entryDate,
            TO_CHAR(PS_Enrollment.ExitDate, '~[dateformat]') as exitDate
        FROM
            PS_Membership_Reg
        JOIN 
            PS_Enrollment ON PS_Enrollment.StudentID = PS_Membership_Reg.StudentID
            AND
            PS_Enrollment.SchoolID = PS_Membership_Reg.SchoolID
            AND 
            (
                PS_Enrollment.EntryDate BETWEEN TO_DATE('~(gpv.startDate;onlydatecharacters)','~[dateformat]') AND (TO_DATE('~(gpv.endDate;onlydatecharacters)','~[dateformat]'))
                OR
                PS_Enrollment.ExitDate - 1 BETWEEN TO_DATE('~(gpv.startDate;onlydatecharacters)','~[dateformat]') AND (TO_DATE('~(gpv.endDate;onlydatecharacters)','~[dateformat]'))
                OR
                (PS_Enrollment.EntryDate < TO_DATE('~(gpv.startDate;onlydatecharacters)','~[dateformat]') AND PS_Enrollment.ExitDate > (TO_DATE('~(gpv.endDate;onlydatecharacters)','~[dateformat]')))
            )
        JOIN
            Students ON Students.ID = PS_Membership_Reg.StudentID
        WHERE
            PS_Membership_Reg.CalendarDate BETWEEN TO_DATE('~(gpv.startDate;onlydatecharacters)','~[dateformat]') AND (TO_DATE('~(gpv.endDate;onlydatecharacters)','~[dateformat]'))
            AND PS_Membership_Reg.SchoolID = ~(curschoolid)
            ~[if.~(gpv.studentSelection)=cur] 
                AND Students.DCID IN (SELECT dcid FROM ~[temp.table.current.selection:students])
            [/if]
        GROUP BY
            PS_Membership_Reg.StudentID,
            Students.DCID,
            PS_Enrollment.EntryDate,
            PS_Enrollment.ExitDate
      ;]
        {
            "dne": "~(dne;JSON)",
            "studentID": "~(studentID;JSON)",
            "dcid": "~(dcid;JSON)",
            "entryDate": "~(entryDate;JSON)",
            "exitDate": "~(exitDate;JSON)"
        },
      [/tlist_sql]{}
]