Home set all values from column as variable
Reply: 0

set all values from column as variable

user986 Published in June 19, 2018, 6:21 pm

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? Cursor approach?

Thank you so much!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.319332 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO