I am getting an error – ‘Could not start transaction; too many transaction already nested.’ when I use 7 union statements for a query. If I remove one union statements and make it 6 then everything runs perfectly. Any help to resolve this issue will be very valuable.
Thanks!
The tables I am using:
School_TBL consists of a courses column, and a student column. One student can take more than course (so it is a multi-valued field)
Here is the SQL statement:
select 'John' as Student Name, Sum(IIf([CourseID]=1,1,0)) as Math, Sum(IIf([CourseID]=2,1,0)) AS English
From School_TBL
where (School_TBL.StudentID.value = 2 and School_TBL.CourseID.Value=1)
GROUP BY School_TBL.StudentID.Value
UNION ALL
select 'Jane' as Student Name, Sum(IIf([CourseID]=1,1,0)) as Math, Sum(IIf([CourseID]=2,1,0)) AS English
From School_TBL
where (School_TBL.StudentID.value = 3 and School_TBL.CourseID.Value=1)
GROUP BY School_TBL.StudentID.Value
UNION ALL
select 'Jim' as Student Name, Sum(IIf([CourseID]=1,1,0)) as Math, Sum(IIf([CourseID]=2,1,0)) AS English
From School_TBL
where (School_TBL.StudentID.value = 4 and School_TBL.CourseID.Value=1)
GROUP BY School_TBL.StudentID.Value
UNION ALL
select 'Hank' as Student Name, Sum(IIf([CourseID]=1,1,0)) as Math, Sum(IIf([CourseID]=2,1,0)) AS English
From School_TBL
where (School_TBL.StudentID.value = 5 and School_TBL.CourseID.Value=1)
GROUP BY School_TBL.StudentID.Value
UNION ALL
select 'Jay' as Student Name, Sum(IIf([CourseID]=1,1,0)) as Math, Sum(IIf([CourseID]=2,1,0)) AS English
From School_TBL
where (School_TBL.StudentID.value = 6 and School_TBL.CourseID.Value=1)
GROUP BY School_TBL.StudentID.Value
UNION ALL
select 'Anna' as Student Name, Sum(IIf([CourseID]=1,1,0)) as Math, Sum(IIf([CourseID]=2,1,0)) AS English
From School_TBL
where (School_TBL.StudentID.value = 7 and School_TBL.CourseID.Value=1)
GROUP BY School_TBL.StudentID.Value
UNION ALL
select 'Amy' as Student Name, Sum(IIf([CourseID]=1,1,0)) as Math, Sum(IIf([CourseID]=2,1,0)) AS English
From School_TBL
where (School_TBL.StudentID.value = 8 and School_TBL.CourseID.Value=1)
GROUP BY School_TBL.StudentID.Value
UNION ALL
select 'Jason' as Student Name, Sum(IIf([CourseID]=1,1,0)) as Math, Sum(IIf([CourseID]=2,1,0)) AS English
From School_TBL
where (School_TBL.StudentID.value = 9 and School_TBL.CourseID.Value=1)
GROUP BY School_TBL.StudentID.Value
YOu need a second table that holds student details, if you don’t already have one. You only need one select statement that does a join on that table to extract the student name