I think the issue in the query is that the return clause corresponding to the let clause is missing. The query has a FLWOR expression (for $st...) nested in another FLWOR expression (let $query_a...) and there must be two return clauses.
Here is a fixed query, with the indentation set to facilitate readability (it is assuming that $student
and $transcript
are properly bound to sequences of student objects resp. of transcript objects):
let $query_a :=
for $st in $student
where (
some $t in $transcript
satisfies ($t.ssn = $st.ssn and $t.dcode = "CS" and $t.cno = 530)
)
return {
ssn: $st.ssn,
name: $st.name,
major: $st.major,
status: $st.status
}
return $query_a
Note that $query_a
cannot be the "null" value (which is a sequence of one atomic item, the null item): if no item in the sequence $student passes the predicate filter, then $query_a
will be the empty sequence of items.
You can then test if a sequence is empty or not with the function empty:
if(empty($sequence))
then ...
else ...