Q:

CASE expression in ListAgg()

I am including a ListAgg in my query using a case expression. 
However I keep receiving the error "missing keyword." I've used the format I've found in other answers here, but it still isn't working.
    Select
    SC.NAME,
    listagg(case sc.COURSE_REFERENCE_NUMBER
    when  sc.department = 'AVSC' and sc.course_number in ('100', '200', 
    '300', '400') end, ', ')
    within group (order by sc.COURSE_REFERENCE_NUMBER) as avsc_crn

    from odsmgr.student_course SC
    where SC.ACADEMIC_PERIOD = '201990'

The exact message is: 

Server error number: 003000
  OraOLEDB : ORA-00905: missing keyword

A:

Your case syntax is off.  You need a then clause:
listagg(case when  sc.department = 'AVSC' and sc.course_number in ('100', '200', '300', '400')
             then sc.COURSE_REFERENCE_NUMBER
         end, ', ') within group (order by sc.COURSE_REFERENCE_NUMBER) as avsc_crn

