Here is my example and I appreciate for your help!
I created a temp_table with two columns: agency_id and budget. As a next step, I need to use the agency_id to find out the latest date in which the budget was reported, which varies of course. Therefore, I thought to set the column agency_id as a variable and plug it into the query that generates the data with the latest reporting date.
This is my code which fails:
declare @agency int
set @agency = (select agency_id from ##temp1)
However, it gives me this error message:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
And this is how I wanted to use it:
select max(report_date), @agency from budgets
How can I solve this?
Thank you so much!