People sometimes indicated a desire to output all PGM and/or AUT statuses that are relevant on one line. While Analytics allows a comfortable way to drill in and contrast program involvements or authorization status, and our Custom Reports allow for the same in its own way as well, having this ability in SQL can also be nice. The building of such a SQL expression may also prove useful in other ways or be more conveniently run from the Aeries interface itself in the future. Exciting things happen with time and all the time with Aeries.
These three examples can be run relatively easy as is or by specifying a single school where indicated.
Here's a video showing it being run...
https://training.aeries.net/jared/PGM_AUT_status
PGM:
Example Output (PGM):
SC | SN | ID | LN | FN | MN | GR | Description_LF | Description_SP | Description_TG | NSLP | SpEd | 504 Accommodation Plan | NCLB Title I Part A Basic Targeted | Gifted and Talented Education (GATE) | Title I Part C Migrant | Tutoring | Educational Options: Advancement Via Individual Determination (AVID) | Foster Program | Homeless Program |
994 | 1 | 99400001 | Abbott | Allan | James | 12 | English Learner | Regular Program | Active | F | Y | No | Yes | Yes | No | No | No | Yes | No |
994 | 2 | 99400002 | Abdelnour | Alice |
| 9 | English Learner | Regular Program | Active |
|
| No | No | Yes | No | No | No | No | No |
994 | 3 | 99400003 | Abdo | Alice | A | 9 | English Only | Regular Program | Active |
|
| No | No | No | No | No | No | Yes | No |
994 | 4 | 99400004 | Abdo | Arnold | A | 10 | English Only | Regular Program | Active |
|
| Yes | No | No | No | No | No | No | No |
994 | 5 | 99400005 | Abea | Ayrianna | J | 12 | English Learner | Regular Program | Active |
| Y | No | No | No | No | No | No | No | No |
994 | 6 | 99400006 | Abejon | Tanya | A | 10 | English Only | Regular Program | Active |
|
| No | No | No | No | No | No | No | No |
994 | 7 | 99400007 | Abesamis | Siobhan | A | 12 | English Only | Regular Program | Active |
|
| No | No | No | No | No | No | No | No |
994 | 8 | 99400008 | Abesamis | Tatiana | J | 9 | English Only | Regular Program | Active |
|
| No | No | No | No | No | No | Yes | No |
994 | 9 | 99400009 | Abney | Jessica | Marie | 12 |
| Regular Program | Active |
|
| No | No | No | No | No | No | No | No |
AUT:
Example Output (AUT):
sc | sn | id | ln | fn | mn | gr | tg | lf | sp | Include in Student Address Directory Listing | Voluntary Student Accident Insurance | Use the Internet | Release Records to Military | Photo Use in District Brochures and Press Releases | Surveys Permitted |
994 | 1 | 99400001 | Abbott | Allan | James | 12 |
| L |
| Yes | Yes | Yes | No | No | No |
994 | 2 | 99400002 | Abdelnour | Alice |
| 9 |
| L |
|
|
|
|
|
|
|
994 | 3 | 99400003 | Abdo | Alice | A | 9 |
| E |
|
|
|
|
|
|
|
994 | 4 | 99400004 | Abdo | Arnold | A | 10 |
| E |
|
|
|
|
|
|
|
994 | 5 | 99400005 | Abea | Ayrianna | J | 12 |
| L |
|
|
|
|
|
|
|
994 | 6 | 99400006 | Abejon | Tanya | A | 10 |
| E |
|
|
|
|
|
|
|
994 | 7 | 99400007 | Abesamis | Siobhan | A | 12 |
| E |
|
|
|
|
|
|
|
994 | 8 | 99400008 | Abesamis | Tatiana | J | 9 |
| E |
|
|
|
|
|
|
|
994 | 9 | 99400009 | Abney | Jessica | Marie | 12 |
| F |
|
|
|
|
|
|
|
Both PGM and AUT status combined:
Example Output (PGM and AUT):
declare @DynaQuery nvarchar(max) = ''
select @DynaQuery += N'
declare @day datetime = convert(char(10),current_timestamp,101)
--declare @day datetime = ''1/1/2015'' --or specify a specific date instead of the current moment and do not use the line above.
--Specify a school number in the next line. NOTE: You can remark out line 60 to see entire district
declare @sc int = 994
select SC, SN, ID, LN, FN, MN, GR,
isnull([GD_STU_LF_STU_LF].[DE],'''') AS [Description_LF],
isnull([GD_STU_SP_STU_SP].[DE],'''') AS [Description_SP],
isnull([GD_STU_TG_STU_TG].[DE],'''') AS [Description_TG],
isnull(
(select top 1 cd
from fre
where id = stu.id and esd <= @day and (eed is null or eed >= @day)
order by esd desc, sq desc)
,'''' ) as NSLP,
isnull((select ''Y'' from cse where id = stu.id and di <> '''' and xd is null and del = 0),'''') SpEd,
'
select @DynaQuery += N'
case
when id in (select pid from pgm where cd = ''' + CD + ''' and (psd <= @day and (ped >= @day or ped is null)) and pid = stu.id and del = 0) then ''Yes''
when id in (select pid from pgm where cd = ''' + CD + ''' and (esd <= @day and (eed >= @day or eed is null)) and pid = stu.id and del = 0) then ''Eligible''
when id in (select pid from pgm where cd = ''' + CD + ''' and esd is null and psd is null and pid = stu.id and del = 0) then ''Null Start''
when id in (select pid from pgm where cd = ''' + CD + ''' and psd > @day and pid = stu.id and del = 0) then ''Future Yes''
when id in (select pid from pgm where cd = ''' + CD + ''' and esd > @day and pid = stu.id and del = 0) then ''Future Eligible''
when id in (select pid from pgm where cd = ''' + CD + ''' and esd <= @day and eed <= @day and pid = stu.id and del = 0) then ''Previous Yes''
when id in (select pid from pgm where cd = ''' + CD + ''' and esd <= @day and eed <= @day and pid = stu.id and del = 0) then ''Previous Eligible''
else ''No''
--end as ''PGM_' + cd + N''' --PGM_CODE as Header
end as ''' + left(de,128) + N''' --Description as Header
,'
from (select * from (select cd, replace(de,'''','''''') as de from USYSGCOD where tc = 'pgm' and fc = 'cd' and del = 0
union
select cd, replace(de,'''','''''') as de from COD where tc = 'pgm' and fc = 'cd' and del = 0 and cd not in (select cd from USYSGCOD where tc = 'pgm' and fc = 'cd' and del = 0)) codes where de not like '%no longer%' and de not like '%old code%' and cd <> ''
and cd in (select distinct pgm.cd from stu inner join pgm on stu.id = pgm.pid where stu.del = 0
and stu.tg = ''
and pgm.cd <> '')
) PGMcodes
if exists (select top 1 1 from (select cd, de from COD where tc = 'aut' and fc = 'cd' and del = 0) codes where cd <> ''
and cd in (select distinct cd from aut where del = 0 and pid in (select distinct id from stu where del = 0 and tg = ''))
and cd in (select distinct cd from aut where del = 0)
)
begin
select @DynaQuery += '
case
when id in (select pid from aut where cd = ''' + CD + ''' and st = ''1'' and (dt <= @day and (sdt <= @day or sdt is null) and (eed >= @day or eed is null)) and del = 0 and pid = stu.id) and id not in (select pid from aut where cd = ''' + CD + ''' and st = ''2'' and (dt <= @day and (sdt <= @day or sdt is null) and (eed >= @day or eed is null)) and del = 0 and pid = stu.id) then ''Yes''
when id in (select pid from aut where cd = ''' + CD + ''' and st = ''1'' and (dt <= @day and (sdt <= @day or sdt is null) and (eed >= @day or eed is null)) and del = 0 and pid = stu.id) and id in (select pid from aut where cd = ''' + CD + ''' and st = ''2'' and (dt <= @day and (sdt <= @day or sdt is null) and (eed >= @day or eed is null)) and del = 0 and pid = stu.id) then ''Conflict''
when id not in (select pid from aut where cd = ''' + CD + ''' and st = ''1'' and (dt <= @day and (sdt <= @day or sdt is null) and (eed >= @day or eed is null)) and del = 0 and pid = stu.id) and id not in (select pid from aut where cd = ''' + CD + ''' and st = ''2'' and (dt <= @day and (sdt <= @day or sdt is null) and (eed >= @day or eed is null)) and del = 0 and pid = stu.id) then ''''
else ''No''
end as [' + left(de,128) + '] --AUT description as header
--end as ''AUT_' + cd + ''' --AUT_CD as header
,'
from (select * from (select cd, de from COD where tc = 'aut' and fc = 'cd' and del = 0) codes where cd <> ''
and cd in (select distinct cd from aut where del = 0 and pid in (select distinct id from stu where del = 0 and tg = ''))
and cd in (select distinct cd from aut where del = 0)
) AUTcodes
set @DynaQuery = left(@DynaQuery, len(@DynaQuery) - 1)
end
set @DynaQuery = left(@DynaQuery, len(@DynaQuery) - 1)
select @DynaQuery += N'
from stu
CROSS APPLY dbo.Get_Description_New(@sc, ''STU'', ''LF'', [STU].[LF]) AS [GD_STU_LF_STU_LF]
CROSS APPLY dbo.Get_Description_New(@sc, ''STU'', ''SP'', [STU].[SP]) AS [GD_STU_SP_STU_SP]
CROSS APPLY dbo.Get_Description_New(@sc, ''STU'', ''TG'', [STU].[TG]) AS [GD_STU_TG_STU_TG]
where del = 0
and tg = '''' --remark out this line to include inactives
and sc = @sc --remark this line out to do the whole district (note this is potentially a large SQL burden!
'
exec (@DynaQuery)
SC | SN | ID | LN | FN | MN | GR | Description_LF | Description_SP | Description_TG | NSLP | SpEd | 504 Accommodation Plan | NCLB Title I Part A Basic Targeted | Gifted and Talented Education (GATE) | Title I Part C Migrant | Tutoring | Educational Options: Advancement Via Individual Determination (AVID) | Foster Program | Homeless Program | Include in Student Address Directory Listing | Voluntary Student Accident Insurance | Use the Internet | Release Records to Military | Photo Use in District Brochures and Press Releases | Surveys Permitted |
994 | 1 | 99400001 | Abbott | Allan | James | 12 | English Learner | Regular Program | Active | F | Y | No | Yes | Yes | No | No | No | Yes | No | Yes | Yes | Yes | No | No | No |
994 | 2 | 99400002 | Abdelnour | Alice |
| 9 | English Learner | Regular Program | Active |
|
| No | No | Yes | No | No | No | No | No |
|
|
|
|
|
|
994 | 3 | 99400003 | Abdo | Alice | A | 9 | English Only | Regular Program | Active |
|
| No | No | No | No | No | No | Yes | No |
|
|
|
|
|
|
994 | 4 | 99400004 | Abdo | Arnold | A | 10 | English Only | Regular Program | Active |
|
| Yes | No | No | No | No | No | No | No |
|
|
|
|
|
|
994 | 5 | 99400005 | Abea | Ayrianna | J | 12 | English Learner | Regular Program | Active |
| Y | No | No | No | No | No | No | No | No |
|
|
|
|
|
|
994 | 6 | 99400006 | Abejon | Tanya | A | 10 | English Only | Regular Program | Active |
|
| No | No | No | No | No | No | No | No |
|
|
|
|
|
|
994 | 7 | 99400007 | Abesamis | Siobhan | A | 12 | English Only | Regular Program | Active |
|
| No | No | No | No | No | No | No | No |
|
|
|
|
|
|
994 | 8 | 99400008 | Abesamis | Tatiana | J | 9 | English Only | Regular Program | Active |
|
| No | No | No | No | No | No | Yes | No |
|
|
|
|
|
|
994 | 9 | 99400009 | Abney | Jessica | Marie | 12 |
| Regular Program | Active |
|
| No | No | No | No | No | No | No | No |
|
|
|
|
|
|
994 | 12 | 99400012 | Abrego | Alice | A | 9 |
| Regular Program | Active |
|
| No | No | No | No | No | No | No | No |
|
|
|
|
|
|
994 | 15 | 99400015 | Aceves | Steven |
| 12 | English Learner | Regular Program | Active |
|
| No | No | No | No | No | No | No | No |
|
|
|
|
|
|
994 | 16 | 99400016 | Acharya | Josiah |
| 11 | English Learner | Regular Program | Active |
|
| No | No | No | No | No | No | No | No |
|
|
|
|
|
|
994 | 17 | 99400017 | Ackermann | Kathrin | Ann | 10 | English Only | Regular Program | Active |
|
| No | No | No | No | No | No | No | No |
|
|
|
|
|
|