I'm using SQL Server Report Builder 3.0 to create a report.
I have two tables and I want to look up a value in one table and then use that to select a value from the second table. Example as follows:
Table : Staff
| staff_id | Surname |
| -------- | ------- |
| 1 | Smith |
| 2 | Jones |
Table: Courses
| Teacher | Course |
| -------- | ------- |
| 1 | French |
| 2 | German |
Dataset1: SELECT staff_id FROM staff WHERE surname='Smith'
Dataset2: SELECT course FROM courses WHERE teacher = {staff_id from Dataset1}
But I can't figure out how to pass the value from Dataset1 to the query in Dataset2
I've tried getting the value into a Variable called teacher_id using a lookup against the other dataset and then the query for Dataset2 becomes
SELECT course FROM courses WHERE teacher = @teacher_id
but I get the error
The expression used for the calculated field 'teacher_id' includes an aggregate, RowNumber, RunningValue, Previous or lookup function. Aggregate, RowNumber, RunningValue, Previous and lookup functions cannot be used in calculated field expressions.
Is it possible to do what I need to?
Many thanks
Edit: Apologies - I can't seem to format the tables correctly, but they are just 2 cols by 2 rows so should be easily understood