I'm trying to pass a value from a table into a variable which I can then use in a query. The problem is that I need the variable to have multiple values, which I've never done before. Below is an example of what I'm trying to do.
CompanyID has multiple values for control number. How would I be able to pass multiple values into the variable? The query I'm using is using Open Query so I can't join to a temp table.
declare @t table( companyid int, control_number int)
insert into @t
values(5555, 777),
(5555, 720),
(5555, 234),
(111, 345),
(111, 356)
select *
from @t
declare @CN int
set @CN = (select control_number from @t where companyid = 5555)
select *
from @table
where control_number IN(@CN)